Created
April 11, 2024 20:11
-
-
Save ShawonAshraf/628640f1b39b427e354476f650735d97 to your computer and use it in GitHub Desktop.
Revisions
-
Shawon Ashraf created this gist
Apr 11, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import openai from pydantic import BaseModel, Field import json class ResponseStructure(BaseModel): bookname: str = Field(..., title="Book Name") author: str = Field(..., title="Author") reading_list_name: str = Field(..., title="Reading List Name") client = openai.Client( api_key="ollama", base_url="http://gandalf:8000/v1" ) messages = [ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, {"role": "user", "content": "Add the book '1984' by 'George Orwell' to the 'Currently Reading' list."}, ] chat_response = client.chat.completions.create( model="solidrust/Hermes-2-Pro-Mistral-7B-AWQ", messages=messages,# type: ignore response_format={"type": "json_object", "schema": ResponseStructure.model_json_schema()}, # type: ignore temperature=0.0, ) # json_obj = json.loads(chat_response.choices[0].message.content) # type: ignore # print(json_obj) print(chat_response.choices[0].message.content)