fix tests

This commit is contained in:
Adil Hafeez 2025-03-19 15:04:22 -07:00
parent 786bb40253
commit 00cf848a8f
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
4 changed files with 35 additions and 5 deletions

View file

@ -504,6 +504,10 @@ impl HttpContext for StreamContext {
};
if self.streaming_response {
if body_utf8 == "data: [DONE]\n" {
return Action::Continue;
}
let chat_completions_chunk_response_events =
match ChatCompletionStreamResponseServerEvents::try_from(body_utf8.as_str()) {
Ok(response) => response,
@ -517,7 +521,10 @@ impl HttpContext for StreamContext {
};
if chat_completions_chunk_response_events.events.is_empty() {
debug!("empty streaming response");
debug!(
"cound't parse any streaming events: body str: {}",
body_utf8
);
return Action::Continue;
}

View file

@ -40,7 +40,7 @@ impl HttpContext for StreamContext {
if endpoints.len() == 1 {
let (name, _) = endpoints.iter().next().unwrap();
debug!("Setting ARCH_PROVIDER_HINT_HEADER to {}", name);
self.set_http_request_header(ARCH_ROUTING_HEADER, Some(&name));
self.set_http_request_header(ARCH_ROUTING_HEADER, Some(name));
} else {
warn!("Need single endpoint when use_agent_orchestrator is set");
self.send_server_error(

View file

@ -26,13 +26,14 @@ class ChatCompletionsRequest(BaseModel):
openai_client = openai.OpenAI(
api_key=" -- ", # Replace with your OpenAI API key
api_key="None", # archgw picks the API key from the config file
base_url="http://host.docker.internal:12000/v1",
)
def call_openai(messages: List[Dict[str, str]], stream: bool):
completion = openai_client.chat.completions.create(
model="gpt-4o", # archgw picks the default LLM configured in the config file
model="None", # archgw picks the default LLM configured in the config file
messages=messages,
stream=stream,
)
@ -93,7 +94,12 @@ AGENTS = {
@app.post("/v1/chat/completions")
def completion_api(req: ChatCompletionsRequest, request: Request):
agent_name = req.metadata.get("agent-name", "unknown_agent")
agent = AGENTS.get(agent_name, AGENTS["unknown_agent"])
agent = AGENTS.get(agent_name)
logger.info(f"Routing to agent: {agent_name}")
return agent.handle(req)
@app.get("/healthz")
async def healthz():
return {"status": "ok"}

View file

@ -0,0 +1,17 @@
POST http://localhost:12000/v1/chat/completions
Content-Type: application/json
{
"model": "--",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant.\n"
},
{
"role": "user",
"content": "I want to sell red shoes"
}
],
"stream": true
}