File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 55con = mindsdb_sdk .connect ()
66
77open_ai_key = os .getenv ('OPENAI_API_KEY' )
8- model_name = 'gpt-4 '
8+ model_name = 'gpt-4o '
99
1010# Now create an agent that will use the model we just created.
1111agent = con .agents .create (name = f'mindsdb_retrieval_agent_{ model_name } _{ uuid4 ().hex } ' ,
12- model = 'gpt-4' ,
12+ model = model_name ,
1313 params = {'return_context' : True })
1414
1515agent .add_file ('./data/tokaido-rulebook.pdf' , 'rule book for the board game Tokaido' )
1616
17-
1817question = "what are the rules for the game takaido?"
1918answer = agent .completion ([{'question' : question , 'answer' : None }])
2019print (answer .context )
Original file line number Diff line number Diff line change 1+ import mindsdb_sdk
2+ from uuid import uuid4
3+ import os
4+
5+ con = mindsdb_sdk .connect ()
6+
7+ open_ai_key = os .getenv ('OPENAI_API_KEY' )
8+ model_name = 'gpt-4o'
9+
10+ # Now create an agent that will use the model we just created.
11+ agent = con .agents .create (name = f'mindsdb_retrieval_agent_{ model_name } _{ uuid4 ().hex } ' ,
12+ model = model_name ,
13+ params = {'return_context' : True })
14+
15+ agent .add_file ('./data/tokaido-rulebook.pdf' , 'rule book for the board game Tokaido' )
16+
17+ question = "what are the rules for the game takaido?"
18+
19+ # Stream the completion
20+ completion_stream = agent .completion_stream ([{'question' : question , 'answer' : None }])
21+
22+ # Process the streaming response
23+ full_response = ""
24+ for chunk in completion_stream :
25+ print (chunk ) # Print the entire chunk for debugging
26+ if isinstance (chunk , dict ):
27+ if 'output' in chunk :
28+ full_response += chunk ['output' ]
29+ elif isinstance (chunk , str ):
30+ full_response += chunk
31+
32+ print ("\n \n Full response:" )
33+ print (full_response )
You can’t perform that action at this time.
0 commit comments