Skip to content

Commit

Permalink
docs: removed List and refactored to list
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanleomk committed Oct 24, 2024
1 parent b407427 commit 87b184e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions docs/blog/posts/llm-as-reranker.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ First, let's set up our environment with the necessary imports:
import instructor
from openai import OpenAI
from pydantic import BaseModel, Field, field_validator
from typing import List

client = instructor.from_openai(OpenAI())
```
Expand All @@ -63,11 +62,11 @@ class Label(BaseModel):


class RerankedResults(BaseModel):
labels: List[Label] = Field(description="List of labeled and ranked chunks")
labels: list[Label] = Field(description="List of labeled and ranked chunks")

@field_validator("labels")
@classmethod
def model_validate(cls, v: List[Label]) -> List[Label]:
def model_validate(cls, v: list[Label]) -> list[Label]:
return sorted(v, key=lambda x: x.relevancy, reverse=True)
```

Expand All @@ -78,7 +77,7 @@ These models ensure that our LLM's output is structured and includes a list of l
Next, we'll create a function that uses our LLM to rerank a list of text chunks based on their relevance to a query:

```python
def rerank_results(query: str, chunks: List[dict]) -> RerankedResults:
def rerank_results(query: str, chunks: list[dict]) -> RerankedResults:
return client.chat.completions.create(
model="gpt-4o-mini",
response_model=RerankedResults,
Expand Down

0 comments on commit 87b184e

Please sign in to comment.