Skip to content

Commit 585c8c3

Browse files
authored
update on latest release from gradient-python-sdk (embeddings batching) and async.
2 parents e267264 + 776bb3c commit 585c8c3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ GRADIENT_WORKSPACE_ID=...
1515

1616
1. Clone this repo
1717
2. Run `poetry install`
18-
3. Run `poetry run fine_tune` to run fine-tuning example, or `poetry run embeddings` to run embeddings example
18+
3. Run any of the following:
19+
- `poetry run fine_tune`
20+
- `poetry run embeddings`
21+
- `poetry run guidance`
1922

2023
## Example
2124

Diff for: gradient_sdk_python_example/embeddings.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
load_dotenv()
44
from gradientai import Gradient
5-
5+
import asyncio
66

77
def main() -> None:
8+
print("running sync embeddings example")
89
gradient = Gradient()
910

1011
embeddings_model = gradient.get_embeddings_model(slug="bge-large")
1112

12-
generate_embeddings_response = embeddings_model.generate_embeddings(
13+
generate_embeddings_response = embeddings_model.embed(
1314
inputs=[
1415
{
1516
"input": "Multimodal brain MRI is the preferred method to evaluate for acute ischemic infarct and ideally should be obtained within 24 hours of symptom onset, and in most centers will follow a NCCT"
@@ -28,6 +29,31 @@ def main() -> None:
2829

2930
gradient.close()
3031

32+
async def main_async() -> None:
33+
print("running async embeddings example")
34+
gradient = Gradient()
35+
36+
embeddings_model = gradient.get_embeddings_model(slug="bge-large")
37+
38+
generate_embeddings_response = await embeddings_model.aembed(
39+
inputs=[
40+
{
41+
"input": "Multimodal brain MRI is the preferred method to evaluate for acute ischemic infarct and ideally should be obtained within 24 hours of symptom onset, and in most centers will follow a NCCT"
42+
},
43+
{
44+
"input": "CTA has a higher sensitivity and positive predictive value than magnetic resonance angiography (MRA) for detection of intracranial stenosis and occlusion and is recommended over time-of-flight (without contrast) MRA"
45+
},
46+
{
47+
"input": "Echocardiographic strain imaging has the advantage of detecting early cardiac involvement, even before thickened walls or symptoms are apparent"
48+
},
49+
],
50+
)
51+
52+
for embedding in generate_embeddings_response.embeddings:
53+
print(f"generated embedding: {embedding.embedding}")
54+
55+
gradient.close()
3156

3257
if __name__ == "__main__":
3358
main()
59+
asyncio.run(main_async())

0 commit comments

Comments
 (0)