-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_models.py
67 lines (51 loc) · 1.82 KB
/
get_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
import instructor
from openai import OpenAI
from pydantic import BaseModel, Field
from dotenv import load_dotenv
from typing import List
load_dotenv()
class Model(BaseModel):
enum: str = Field(...)
serialized_name: str = Field(...)
description: str = Field(...)
class ModelsList(BaseModel):
models: List[Model] = Field(...)
url = "https://raw.githubusercontent.com/andthattoo/ollama-workflows/refs/heads/main/src/program/models.rs"
# Download the file
response = requests.get(url)
# Get content as str
content = response.text
# Apply the patch to the OpenAI client
# enables response_model, validation_context keyword
client = instructor.from_openai(OpenAI())
def models(models_content: str) -> ModelsList:
return client.chat.completions.create(
model="gpt-4o",
temperature=0,
response_model=ModelsList,
messages=[
{
"role": "system",
"content": "You are a world class information extraction tool.",
},
{"role": "user", "content": f"{models_content}"},
{
"role": "user",
"content": f"Extract the models info from the given content.",
},
],
)
if __name__ == "__main__":
models_list = models(content)
# Open or overwrite the md file
with open("docs/how-to/models.md", "w") as file:
file.write(f"# Models\n\n")
file.write(f"See available models in Dria Network below:\n\n")
file.write("### Available Models\n\n")
file.write("| Enum | Serialized Name | Description |\n")
file.write("| :---: | :---: | :---: |\n")
for model in models_list.models:
file.write(
f"| `{model.enum}` | `{model.serialized_name}` | {model.description} |\n"
)