MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / run_agent

Function run_agent

tests/explorer/explorer_test.py:393–438  ·  view source on GitHub ↗
(proxy_url, model_path: str, stream: bool)

Source from the content-addressed store, hash-verified

391
392
393def run_agent(proxy_url, model_path: str, stream: bool):
394 proxy_client = TrinityClient(proxy_url=proxy_url)
395 openai_client = proxy_client.get_openai_client()
396 contents = [
397 "Hello, how are you?",
398 "What is the capital of China?",
399 "Tell me a joke.",
400 "Explain the theory of relativity.",
401 "What is the meaning of life?",
402 "How does a computer work?",
403 "What is the weather like today?",
404 "Can you recommend a good book?",
405 "What is the best way to learn programming?",
406 "Describe the process of photosynthesis.",
407 ]
408 if stream:
409 stream_response = openai_client.chat.completions.create(
410 model=model_path,
411 messages=[{"role": "user", "content": random.choice(contents)}],
412 stream=True,
413 )
414 response_id = None
415 text_parts = []
416 for chunk in stream_response:
417 if response_id is None and getattr(chunk, "id", None):
418 response_id = chunk.id
419 if not getattr(chunk, "choices", None):
420 continue
421 delta = chunk.choices[0].delta
422 if delta is None:
423 continue
424 content = getattr(delta, "content", None)
425 if content:
426 text_parts.append(content)
427
428 if response_id is not None:
429 proxy_client.feedback(reward=2.0, msg_ids=[response_id])
430 return "".join(text_parts)
431 else:
432 response = openai_client.chat.completions.create(
433 model=model_path,
434 messages=[{"role": "user", "content": random.choice(contents)}],
435 stream=False,
436 )
437 proxy_client.feedback(reward=2.0, msg_ids=[response.id])
438 return response.choices[0].message.content
439
440
441class ServeTest(RayUnittestBaseAsync):

Callers

nothing calls this directly

Calls 4

get_openai_clientMethod · 0.95
feedbackMethod · 0.95
TrinityClientClass · 0.90
createMethod · 0.80

Tested by

no test coverage detected