MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / ChatCompletion

Class ChatCompletion

optillm/inference.py:1696–1741  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1694 self.reasoning_tokens = reasoning_tokens
1695
1696class ChatCompletion:
1697 def __init__(self, response_dict: Dict):
1698 self.id = response_dict["id"]
1699 self.object = response_dict["object"]
1700 self.created = response_dict["created"]
1701 self.model = response_dict["model"]
1702 self.choices = [
1703 ChatCompletionChoice(
1704 index=choice["index"],
1705 message=choice["message"],
1706 finish_reason=choice["finish_reason"]
1707 )
1708 for choice in response_dict["choices"]
1709 ]
1710 self.usage = ChatCompletionUsage(**response_dict["usage"])
1711
1712 def model_dump(self) -> Dict:
1713 return {
1714 "id": self.id,
1715 "object": self.object,
1716 "created": self.created,
1717 "model": self.model,
1718 "choices": [
1719 {
1720 "index": choice.index,
1721 "message": {
1722 "role": choice.message.role,
1723 "content": choice.message.content,
1724 "logprobs": choice.message.logprobs
1725 } if choice.message.logprobs else {
1726 "role": choice.message.role,
1727 "content": choice.message.content
1728 },
1729 "finish_reason": choice.finish_reason
1730 }
1731 for choice in self.choices
1732 ],
1733 "usage": {
1734 "prompt_tokens": self.usage.prompt_tokens,
1735 "completion_tokens": self.usage.completion_tokens,
1736 "total_tokens": self.usage.total_tokens,
1737 "completion_tokens_details": {
1738 "reasoning_tokens": getattr(self.usage, 'reasoning_tokens', 0)
1739 }
1740 }
1741 }
1742
1743class InferenceClient:
1744 """OpenAI SDK Compatible client for local inference with dynamic model support"""

Calls

no outgoing calls