MCPcopy Create free account
hub / github.com/IlyaRice/RAG-Challenge-2 / APIProcessor

Class APIProcessor

src/api_requests.py:370–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368
369
370class APIProcessor:
371 def __init__(self, provider: Literal["openai", "ibm", "gemini"] ="openai"):
372 self.provider = provider.lower()
373 if self.provider == "openai":
374 self.processor = BaseOpenaiProcessor()
375 elif self.provider == "ibm":
376 self.processor = BaseIBMAPIProcessor()
377 elif self.provider == "gemini":
378 self.processor = BaseGeminiProcessor()
379
380 def send_message(
381 self,
382 model=None,
383 temperature=0.5,
384 seed=None,
385 system_content="You are a helpful assistant.",
386 human_content="Hello!",
387 is_structured=False,
388 response_format=None,
389 **kwargs
390 ):
391 """
392 Routes the send_message call to the appropriate processor.
393 The underlying processor's send_message method is responsible for handling the parameters.
394 """
395 if model is None:
396 model = self.processor.default_model
397 return self.processor.send_message(
398 model=model,
399 temperature=temperature,
400 seed=seed,
401 system_content=system_content,
402 human_content=human_content,
403 is_structured=is_structured,
404 response_format=response_format,
405 **kwargs
406 )
407
408 def get_answer_from_rag_context(self, question, rag_context, schema, model):
409 system_prompt, response_format, user_prompt = self._build_rag_context_prompts(schema)
410
411 answer_dict = self.processor.send_message(
412 model=model,
413 system_content=system_prompt,
414 human_content=user_prompt.format(context=rag_context, question=question),
415 is_structured=True,
416 response_format=response_format
417 )
418 self.response_data = self.processor.response_data
419 return answer_dict
420
421
422 def _build_rag_context_prompts(self, schema):
423 """Return prompts tuple for the given schema."""
424 use_schema_prompt = True if self.provider == "ibm" or self.provider == "gemini" else False
425
426 if schema == "name":
427 system_prompt = (prompts.AnswerWithRAGContextNamePrompt.system_prompt_with_schema

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected