-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.py
More file actions
37 lines (30 loc) · 1016 Bytes
/
test.py
File metadata and controls
37 lines (30 loc) · 1016 Bytes
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
import requests
from concurrent.futures import ThreadPoolExecutor
def get_embedding(text):
url = 'http://localhost:11434/api/embeddings'
payload = {
'model': 'nomic-embed-text',
'prompt': text
}
response = requests.post(url, json=payload)
return response.json()
def get_chat_response(prompt):
url = 'http://localhost:11434/api/chat'
payload = {
'model': 'llama3.2:1b',
'prompt': prompt
}
response = requests.post(url, json=payload)
return response.json()
def main():
text = "Your text here"
prompt = "Hello, how can I assist you today?"
with ThreadPoolExecutor(max_workers=2) as executor:
embedding_future = executor.submit(get_embedding, text)
chat_future = executor.submit(get_chat_response, prompt)
embedding = embedding_future.result()
chat_response = chat_future.result()
print("Embedding:", embedding)
print("Chat Response:", chat_response)
if __name__ == "__main__":
main()