|
4 | 4 | from langchain_core.embeddings import Embeddings
|
5 | 5 | from langchain_core.pydantic_v1 import BaseModel, Field, SecretStr, root_validator
|
6 | 6 | from langchain_core.utils import convert_to_secret_str
|
7 |
| - |
8 | 7 | from openai import OpenAI # type: ignore
|
9 | 8 |
|
10 | 9 |
|
11 | 10 | class FireworksEmbeddings(BaseModel, Embeddings):
|
12 | 11 | """Fireworks embedding model integration.
|
13 | 12 |
|
14 |
| - Setup: |
15 |
| - Install ``langchain_fireworks`` and set environment variable ``FIREWORKS_API_KEY``. |
16 |
| -
|
17 |
| - .. code-block:: bash |
18 |
| -
|
19 |
| - pip install -U langchain_fireworks |
20 |
| - export FIREWORKS_API_KEY="your-api-key" |
| 13 | + Setup: |
| 14 | + Install ``langchain_fireworks`` and set environment variable ``FIREWORKS_API_KEY``. |
21 | 15 |
|
22 |
| - Key init args — completion params: |
23 |
| - model: str |
24 |
| - Name of Fireworks model to use. |
| 16 | + .. code-block:: bash |
25 | 17 |
|
26 |
| - Key init args — client params: |
27 |
| - fireworks_api_key: SecretStr |
28 |
| - Fireworks API key. |
| 18 | + pip install -U langchain_fireworks |
| 19 | + export FIREWORKS_API_KEY="your-api-key" |
29 | 20 |
|
30 |
| - See full list of supported init args and their descriptions in the params section. |
| 21 | + Key init args — completion params: |
| 22 | + model: str |
| 23 | + Name of Fireworks model to use. |
31 | 24 |
|
32 |
| - Instantiate: |
33 |
| - .. code-block:: python |
| 25 | + Key init args — client params: |
| 26 | + fireworks_api_key: SecretStr |
| 27 | + Fireworks API key. |
34 | 28 |
|
35 |
| - from __module_name__ import FireworksEmbeddings |
| 29 | + See full list of supported init args and their descriptions in the params section. |
36 | 30 |
|
37 |
| - model = FireworksEmbeddings( |
38 |
| - model='nomic-ai/nomic-embed-text-v1.5' |
39 |
| - # Use FIREWORKS_API_KEY env var or pass it in directly |
40 |
| - # fireworks_api_key="..." |
41 |
| - ) |
| 31 | + Instantiate: |
| 32 | + .. code-block:: python |
42 | 33 |
|
43 |
| - Embed multiple texts: |
| 34 | + from __module_name__ import FireworksEmbeddings |
44 | 35 |
|
45 |
| - .. code-block:: python |
| 36 | + model = FireworksEmbeddings( |
| 37 | + model='nomic-ai/nomic-embed-text-v1.5' |
| 38 | + # Use FIREWORKS_API_KEY env var or pass it in directly |
| 39 | + # fireworks_api_key="..." |
| 40 | + ) |
46 | 41 |
|
47 |
| - vectors = embeddings.embed_documents(['hello', 'goodbye']) |
48 |
| - # Showing only the first 3 coordinates |
49 |
| - print(len(vectors)) |
50 |
| - print(vectors[0][:3]) |
| 42 | + Embed multiple texts: |
| 43 | + .. code-block:: python |
51 | 44 |
|
52 |
| - .. code-block:: python |
| 45 | + vectors = embeddings.embed_documents(['hello', 'goodbye']) |
| 46 | + # Showing only the first 3 coordinates |
| 47 | + print(len(vectors)) |
| 48 | + print(vectors[0][:3]) |
53 | 49 |
|
54 |
| - 2 |
55 |
| - [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915] |
| 50 | + .. code-block:: python |
56 | 51 |
|
| 52 | + 2 |
| 53 | + [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915] |
57 | 54 |
|
58 |
| - Embed single text: |
59 | 55 |
|
60 |
| - .. code-block:: python |
| 56 | + Embed single text: |
| 57 | + .. code-block:: python |
61 | 58 |
|
62 |
| - input_text = "The meaning of life is 42" |
63 |
| - vector = embeddings.embed_query('hello') |
64 |
| - print(vector[:3]) |
| 59 | + input_text = "The meaning of life is 42" |
| 60 | + vector = embeddings.embed_query('hello') |
| 61 | + print(vector[:3]) |
65 | 62 |
|
66 |
| - .. code-block:: python |
| 63 | + .. code-block:: python |
67 | 64 |
|
68 |
| - [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915] |
| 65 | + [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915] |
69 | 66 | """
|
70 | 67 |
|
71 | 68 | _client: OpenAI = Field(default=None)
|
|
0 commit comments