Pigeon
11/28/2024, 3:23 PMVapi
11/28/2024, 3:25 PMVapi
11/28/2024, 3:25 PMVapi
11/28/2024, 3:26 PMPigeon
11/28/2024, 3:45 PMimport time
from typing import Any
from fastapi import APIRouter
router = APIRouter()
@router.post("/completions", status_code=200)
def respond(payload: dict) -> Any:
"""
Endpoint for receiving responses without authentication.
"""
user_messages = [msg for msg in payload["messages"] if msg["role"] == "user"]
if user_messages:
print(f"User content: {user_messages[-1]['content']}")
print("--------------------------------")
response = {
"id": "chatcmpl-8mcLf78g0quztp4BMtwd3hEj58Uof",
"object": "chat.completion",
"created": int(time.time()),
"model": "gpt-3.5-turbo-0613",
"system_fingerprint": None,
"choices": [
{
"index": 0,
"delta": {"content": "Hi, how are you doing?"},
"logprobs": None,
"finish_reason": "stop",
}
],
}
print("--------------------------------")
print(response)
return response
Pigeon
11/28/2024, 3:45 PMPigeon
11/28/2024, 3:45 PMPigeon
11/28/2024, 3:48 PMPigeon
11/28/2024, 3:48 PMPigeon
11/28/2024, 3:50 PMc4599cea-b165-416c-828f-69c393cbf359
call idPigeon
11/28/2024, 5:21 PM@router.post("/completions", status_code=200)
def respond(payload: dict) -> Any:
"""
Endpoint for receiving responses without authentication.
"""
user_messages = [msg for msg in payload["messages"] if msg["role"] == "user"]
if user_messages:
print(f"User content: {user_messages[-1]['content']}")
print("--------------------------------")
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Hi, how are ya?",
}
],
model="llama3-8b-8192",
)
print("----------------------------")
print(chat_completion.choices[0].message.content)
print(chat_completion.model_dump())
return chat_completion.model_dump()
Groq responded with:
2024-11-28 19:13:39 Hi! I'm just a language model, I don't have feelings like humans do, but I'm here to help you with any questions or tasks you have! How can I assist you today?
2024-11-28 19:13:39 {'id': 'chatcmpl-9d94d051-66b6-4f04-b1f8-2a59d74af156', 'choices': [{'finish_reason': 'stop', 'index': 0, 'logprobs': None, 'message': {'content': "Hi! I'm just a language model, I don't have feelings like humans do, but I'm here to help you with any questions or tasks you have! How can I assist you today?", 'role': 'assistant', 'function_call': None, 'tool_calls': None}}], 'created': 1732814021, 'model': 'llama3-8b-8192', 'object': 'chat.completion', 'system_fingerprint': 'fp_179b0f92c9', 'usage': {'completion_tokens': 41, 'prompt_tokens': 16, 'total_tokens': 57, 'completion_time': 0.034166667, 'prompt_time': 0.000146059, 'queue_time': 0.013842211, 'total_time': 0.034312726}, 'x_groq': {'id': 'req_01jdsw797beewax7v08dgv2arz'}}
Pigeon
11/28/2024, 5:21 PMPigeon
11/28/2024, 5:22 PMc7867d0e-0963-4ad0-aca0-c79ea407cfdb
Pigeon
11/28/2024, 5:22 PMHi! I'm just a language model, I don't have feelings like humans do, but I'm here to help you with any questions or tasks you have! How can I assist you today?
to be TTSed in a phone call. But nothing happens...Pigeon
11/28/2024, 5:23 PMPigeon
11/28/2024, 5:24 PMPigeon
11/28/2024, 5:53 PMHTTP/1.1 200 OK
Server: uvicorn
Content-Length: 744
Content-Type: application/json
Date: Thu, 28 Nov 2024 17:49:37 GMT
With body:
{
"id": "chatcmpl-61a93f6f-2e8a-4632-a965-c5a1e7ad8310",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "Hi! I'm just a language model, so I don't have emotions or feelings like humans do, but I'm \"functioning\" well and ready to help you with any questions or tasks you have! How about you? How's your day going?",
"role": "assistant",
"function_call": null,
"tool_calls": null
}
}
],
"created": 1732816180,
"model": "llama3-8b-8192",
"object": "chat.completion",
"system_fingerprint": "fp_a97cfe35ae",
"usage": {
"completion_tokens": 53,
"prompt_tokens": 16,
"total_tokens": 69,
"completion_time": 0.044166667,
"prompt_time": 0.002902825,
"queue_time": 0.012564495,
"total_time": 0.047069492
},
"x_groq": {
"id": "req_01jdsy94smfm79ppb8fpk248xa"
}
}
Pigeon
11/29/2024, 8:03 AMPigeon
11/29/2024, 2:48 PMPigeon
11/29/2024, 4:07 PMShubham Bajaj
11/29/2024, 4:47 PMPigeon
11/29/2024, 4:47 PMPigeon
11/29/2024, 4:48 PMPigeon
11/29/2024, 4:49 PMShubham Bajaj
11/29/2024, 4:53 PMShubham Bajaj
11/29/2024, 4:54 PMPigeon
11/29/2024, 4:54 PMPigeon
11/29/2024, 4:55 PMPigeon
11/29/2024, 4:55 PMPigeon
11/29/2024, 4:55 PMShubham Bajaj
11/29/2024, 4:56 PMPigeon
11/29/2024, 4:59 PMPigeon
11/29/2024, 5:45 PMShubham Bajaj
12/03/2024, 11:46 AMPigeon
12/04/2024, 7:14 AM