MCPcopy
hub / github.com/BinNong/meet-libai / generate_text

Function generate_text

web/api/api.py:60–93  ·  view source on GitHub ↗
(chat_request: Annotated[ChatRequest, Body()])

Source from the content-addressed store, hash-verified

58
59 @app.post("/v1/chat/completions")
60 def generate_text(chat_request: Annotated[ChatRequest, Body()]):
61 response = get_ai_client().chat.completions.create(
62 model=chat_request.model,
63 messages=[m.model_dump() for m in chat_request.messages],
64 top_p=0.7,
65 temperature=chat_request.temperature,
66 max_tokens=chat_request.max_tokens,
67 stream=chat_request.stream,
68 )
69 """
70 返回示例
71 {
72 "created": 1703487403,
73 "id": "8239375684858666781",
74 "model": "glm-4",
75 "request_id": "8239375684858666781",
76 "choices": [
77 {
78 "finish_reason": "stop",
79 "index": 0,
80 "message": {
81 "content": "智绘蓝图,AI驱动 —— 智谱AI,让每一刻创新成为可能。",
82 "role": "assistant"
83 }
84 }
85 ],
86 "usage": {
87 "completion_tokens": 217,
88 "prompt_tokens": 31,
89 "total_tokens": 248
90 }
91 }
92 """
93 return response.dict()

Callers

nothing calls this directly

Calls 1

get_ai_clientFunction · 0.90

Tested by

no test coverage detected