Created
February 28, 2025 08:45
-
-
Save EvilFreelancer/203cdb6e41f477d7a7447dddef96ff1d to your computer and use it in GitHub Desktop.
Пример использования DeepSeek-R1 8B запущенной через в ollama в режиме Structured Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from openai import OpenAI | |
client = OpenAI(api_key="~", base_url="http://gpu02:11434/v1") | |
system_prompt = """\ | |
The user will provide some examination text. | |
Please parse the "question" and "answer" and output them in JSON format. | |
OUTPUT JSON SCHEMA: | |
{ | |
"question": "provided question", | |
"answer": "what was answered" | |
} | |
""" | |
user_prompt = "Ты точно не рофлишь? Нет, Фил, я серьёзно." | |
messages = [ | |
{"role": "system", "content": system_prompt}, | |
{"role": "user", "content": user_prompt} | |
] | |
response = client.chat.completions.create( | |
model="deepseek-r1:8b", | |
messages=messages, | |
response_format={'type': 'json_object'} | |
) | |
print(json.loads(response.choices[0].message.content)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment