forked from Hamilton-Labs-Org/DSPy-AI-Agents-Experiment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSPy_prompts_example.py
36 lines (22 loc) · 1.74 KB
/
DSPy_prompts_example.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
import os
import dspy
"""Configuring the LM"""
lm = dspy.LM('ollama_chat/llama3.2:1b-instruct-q6_K', api_base='http://localhost:11434', api_key='')
dspy.configure(lm=lm)
"""Letting the user know the LM is configured."""
print("*************************************************" + os.linesep + os.linesep + "Configured the LM" + os.linesep + os.linesep + "*************************************************",)
"""Prompting the User for the LM's prompt."""
print("*************************************************" + os.linesep + os.linesep + "Obtaining user prompt." + os.linesep + os.linesep + "*************************************************",)
input_message = 'Talk to Llama: '
print("*************************************************" + os.linesep + os.linesep )
prompt = input(input_message)
print(os.linesep + os.linesep + "*************************************************")
"""Letting the user know its sending the prompt to the LM."""
print("*************************************************" + os.linesep + os.linesep + "Sending prompt to LM: " + os.linesep + prompt + os.linesep + os.linesep + "*************************************************",)
print("*************************************************" + os.linesep + os.linesep + "Calling the LM directly" + os.linesep + os.linesep + "*************************************************",)
# Calling the LM directly
output_1 = lm(prompt, temperature=0.7) # => ['This is a test!']
output_2 = lm(messages=[{"role": "user", "content": prompt}]) # => ['This is a test!']
print("*************************************************" + os.linesep + os.linesep + "Printing the LM's Output" + os.linesep + os.linesep + "*************************************************",)
print(output_1[0])
print(output_2[0])