style: .. code-block:: admonition translations (#33400)

biiiiiiiiiiiiiiiigggggggg pass
This commit is contained in:
Mason Daugherty
2025-10-09 16:52:58 -04:00
committed by GitHub
parent 50445d4a27
commit 6fc21afbc9
199 changed files with 10133 additions and 10940 deletions

View File

@@ -265,14 +265,13 @@ class ChatFireworks(BaseChatModel):
can be passed in, even if not explicitly saved on this class.
Example:
.. code-block:: python
from langchain_fireworks.chat_models import ChatFireworks
fireworks = ChatFireworks(
model_name="accounts/fireworks/models/llama-v3p1-8b-instruct"
)
```python
from langchain_fireworks.chat_models import ChatFireworks
fireworks = ChatFireworks(
model_name="accounts/fireworks/models/llama-v3p1-8b-instruct"
)
```
"""
@property
@@ -730,191 +729,193 @@ class ChatFireworks(BaseChatModel):
Example: schema=Pydantic class, method="function_calling", include_raw=False:
.. code-block:: python
```python
from typing import Optional
from typing import Optional
from langchain_fireworks import ChatFireworks
from pydantic import BaseModel, Field
from langchain_fireworks import ChatFireworks
from pydantic import BaseModel, Field
class AnswerWithJustification(BaseModel):
'''An answer to the user question along with justification for the answer.'''
class AnswerWithJustification(BaseModel):
'''An answer to the user question along with justification for the answer.'''
answer: str
# If we provide default values and/or descriptions for fields, these will be passed
# to the model. This is an important part of improving a model's ability to
# correctly return structured outputs.
justification: str | None = Field(
default=None, description="A justification for the answer."
)
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(AnswerWithJustification)
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
answer: str
# If we provide default values and/or descriptions for fields, these will be passed
# to the model. This is an important part of improving a model's ability to
# correctly return structured outputs.
justification: str | None = Field(
default=None, description="A justification for the answer."
)
# -> AnswerWithJustification(
# answer='They weigh the same',
# justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
# )
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(AnswerWithJustification)
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> AnswerWithJustification(
# answer='They weigh the same',
# justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
# )
```
Example: schema=Pydantic class, method="function_calling", include_raw=True:
.. code-block:: python
from langchain_fireworks import ChatFireworks
from pydantic import BaseModel
```python
from langchain_fireworks import ChatFireworks
from pydantic import BaseModel
class AnswerWithJustification(BaseModel):
'''An answer to the user question along with justification for the answer.'''
class AnswerWithJustification(BaseModel):
'''An answer to the user question along with justification for the answer.'''
answer: str
justification: str
answer: str
justification: str
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(
AnswerWithJustification, include_raw=True
)
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(
AnswerWithJustification, include_raw=True
)
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> {
# 'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
# 'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
# 'parsing_error': None
# }
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> {
# 'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
# 'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
# 'parsing_error': None
# }
```
Example: schema=TypedDict class, method="function_calling", include_raw=False:
.. code-block:: python
```python
from typing_extensions import Annotated, TypedDict
# IMPORTANT: If you are using Python <=3.8, you need to import Annotated
# from typing_extensions, not from typing.
from typing_extensions import Annotated, TypedDict
from langchain_fireworks import ChatFireworks
from langchain_fireworks import ChatFireworks
class AnswerWithJustification(TypedDict):
'''An answer to the user question along with justification for the answer.'''
class AnswerWithJustification(TypedDict):
'''An answer to the user question along with justification for the answer.'''
answer: str
justification: Annotated[
str | None, None, "A justification for the answer."
]
answer: str
justification: Annotated[
str | None, None, "A justification for the answer."
]
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(AnswerWithJustification)
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(AnswerWithJustification)
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> {
# 'answer': 'They weigh the same',
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
# }
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> {
# 'answer': 'They weigh the same',
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
# }
```
Example: schema=OpenAI function schema, method="function_calling", include_raw=False:
.. code-block:: python
```python
from langchain_fireworks import ChatFireworks
from langchain_fireworks import ChatFireworks
oai_schema = {
"name": "AnswerWithJustification",
"description": "An answer to the user question along with justification for the answer.",
"parameters": {
"type": "object",
"properties": {
"answer": {"type": "string"},
"justification": {
"description": "A justification for the answer.",
"type": "string",
},
oai_schema = {
"name": "AnswerWithJustification",
"description": "An answer to the user question along with justification for the answer.",
"parameters": {
"type": "object",
"properties": {
"answer": {"type": "string"},
"justification": {
"description": "A justification for the answer.",
"type": "string",
},
"required": ["answer"],
},
}
"required": ["answer"],
},
}
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(oai_schema)
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1",
temperature=0,
)
structured_llm = llm.with_structured_output(oai_schema)
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> {
# 'answer': 'They weigh the same',
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
# }
structured_llm.invoke(
"What weighs more a pound of bricks or a pound of feathers"
)
# -> {
# 'answer': 'They weigh the same',
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
# }
```
Example: schema=Pydantic class, method="json_mode", include_raw=True:
.. code-block::
```python
from langchain_fireworks import ChatFireworks
from pydantic import BaseModel
from langchain_fireworks import ChatFireworks
from pydantic import BaseModel
class AnswerWithJustification(BaseModel):
answer: str
justification: str
class AnswerWithJustification(BaseModel):
answer: str
justification: str
llm = ChatFireworks(model="accounts/fireworks/models/firefunction-v1", temperature=0)
structured_llm = llm.with_structured_output(
AnswerWithJustification,
method="json_mode",
include_raw=True
)
structured_llm.invoke(
"Answer the following question. "
"Make sure to return a JSON blob with keys 'answer' and 'justification'. "
"What's heavier a pound of bricks or a pound of feathers?"
)
# -> {
# 'raw': AIMessage(content='{"answer": "They are both the same weight.", "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight."}'),
# 'parsed': AnswerWithJustification(answer='They are both the same weight.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight.'),
# 'parsing_error': None
# }
llm = ChatFireworks(
model="accounts/fireworks/models/firefunction-v1", temperature=0
)
structured_llm = llm.with_structured_output(
AnswerWithJustification, method="json_mode", include_raw=True
)
structured_llm.invoke(
"Answer the following question. "
"Make sure to return a JSON blob with keys 'answer' and 'justification'. "
"What's heavier a pound of bricks or a pound of feathers?"
)
# -> {
# 'raw': AIMessage(content='{"answer": "They are both the same weight.", "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight."}'),
# 'parsed': AnswerWithJustification(answer='They are both the same weight.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight.'),
# 'parsing_error': None
# }
```
Example: schema=None, method="json_mode", include_raw=True:
.. code-block::
```python
structured_llm = llm.with_structured_output(
method="json_mode", include_raw=True
)
structured_llm = llm.with_structured_output(method="json_mode", include_raw=True)
structured_llm.invoke(
"Answer the following question. "
"Make sure to return a JSON blob with keys 'answer' and 'justification'. "
"What's heavier a pound of bricks or a pound of feathers?"
)
# -> {
# 'raw': AIMessage(content='{"answer": "They are both the same weight.", "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight."}'),
# 'parsed': {
# 'answer': 'They are both the same weight.',
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight.'
# },
# 'parsing_error': None
# }
structured_llm.invoke(
"Answer the following question. "
"Make sure to return a JSON blob with keys 'answer' and 'justification'. "
"What's heavier a pound of bricks or a pound of feathers?"
)
# -> {
# 'raw': AIMessage(content='{"answer": "They are both the same weight.", "justification": "Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight."}'),
# 'parsed': {
# 'answer': 'They are both the same weight.',
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The difference lies in the volume and density of the materials, not the weight.'
# },
# 'parsing_error': None
# }
```
""" # noqa: E501
_ = kwargs.pop("strict", None)

View File

@@ -13,10 +13,10 @@ class FireworksEmbeddings(BaseModel, Embeddings):
Install `langchain_fireworks` and set environment variable
`FIREWORKS_API_KEY`.
.. code-block:: bash
pip install -U langchain_fireworks
export FIREWORKS_API_KEY="your-api-key"
```bash
pip install -U langchain_fireworks
export FIREWORKS_API_KEY="your-api-key"
```
Key init args — completion params:
model: str
@@ -30,42 +30,39 @@ class FireworksEmbeddings(BaseModel, Embeddings):
Instantiate:
.. code-block:: python
```python
from langchain_fireworks import FireworksEmbeddings
from langchain_fireworks import FireworksEmbeddings
model = FireworksEmbeddings(
model="nomic-ai/nomic-embed-text-v1.5"
# Use FIREWORKS_API_KEY env var or pass it in directly
# fireworks_api_key="..."
)
model = FireworksEmbeddings(
model="nomic-ai/nomic-embed-text-v1.5"
# Use FIREWORKS_API_KEY env var or pass it in directly
# fireworks_api_key="..."
)
```
Embed multiple texts:
.. code-block:: python
vectors = embeddings.embed_documents(["hello", "goodbye"])
# Showing only the first 3 coordinates
print(len(vectors))
print(vectors[0][:3])
.. code-block:: python
2
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
```python
vectors = embeddings.embed_documents(["hello", "goodbye"])
# Showing only the first 3 coordinates
print(len(vectors))
print(vectors[0][:3])
```
```python
2
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
```
Embed single text:
.. code-block:: python
input_text = "The meaning of life is 42"
vector = embeddings.embed_query("hello")
print(vector[:3])
.. code-block:: python
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
```python
input_text = "The meaning of life is 42"
vector = embeddings.embed_query("hello")
print(vector[:3])
```
```python
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
```
"""
client: OpenAI = Field(default=None, exclude=True) # type: ignore[assignment] # :meta private:

View File

@@ -31,10 +31,9 @@ class Fireworks(LLM):
[Fireworks AI API reference](https://readme.fireworks.ai/)
Example:
.. code-block:: python
response = fireworks.generate(["Tell me a joke."])
```python
response = fireworks.generate(["Tell me a joke."])
```
"""
base_url: str = "https://api.fireworks.ai/inference/v1/completions"