Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Ollama to Autogen / Magentic One #4333

Open
wants to merge 0 commits into
base: main
Choose a base branch
from

Conversation

MervinPraison
Copy link

Why are these changes needed?

  • Added support for a new chat completion client using the Ollama API (OllamaChatCompletionClient).
  • Enhanced image handling with base64 encoding for the Ollama API.
  • Updated environment-based client creation to accommodate the new Ollama client.

Related Issue Number

  • No specific issue linked. You can mention an issue if applicable.

Checks

  • Documentation updated to reflect new changes.
  • Tested locally with Ollama

@MervinPraison
Copy link
Author

@afourney @ekzhu @jackgerrits @husseinmozannar Recreated the Pull requested as per requested.

Here is the original Pull request for reference #4280

@MervinPraison MervinPraison mentioned this pull request Nov 24, 2024
2 tasks
top_p: float = 0.95

class OllamaChatCompletionClient(ChatCompletionClient):
def __init__(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc string like other clients

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, instead of using OllamaConfig, can we use keyword arguments like other clients?

messages: List,
*,
response_format: Optional[Dict[str, str]] = None,
stream: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create method in the protocol has the following arguments:

 async def create(
        self,
        messages: Sequence[LLMMessage],
        tools: Sequence[Tool | ToolSchema] = [],
        # None means do not override the default
        # A value means to override the client default - often specified in the constructor
        json_output: Optional[bool] = None,
        extra_create_args: Mapping[str, Any] = {},
        cancellation_token: Optional[CancellationToken] = None,
    ) -> CreateResult: ...

This method should implement the protocol method, rather than introducing its own arguments.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value must be CreateResult

json_output=True,
)

def extract_role_and_content(self, msg) -> tuple[str, Union[str, List[Union[str, Image]]]]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use private method prefix with _

else:
return 'user', str(msg)

def process_message_content(self, content):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make private

text_parts.append(str(item))
return '\n'.join(text_parts), images

def encode_image(self, image: Image) -> Optional[str]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make priviate

return AssistantMessage(
content=f"Error: Failed to get response from Ollama server: {str(e)}",
source='assistant'
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the following methods:

def actual_usage(self) -> RequestUsage: ...

    def total_usage(self) -> RequestUsage: ...

    def count_tokens(self, messages: Sequence[LLMMessage], tools: Sequence[Tool | ToolSchema] = []) -> int: ...

    def remaining_tokens(self, messages: Sequence[LLMMessage], tools: Sequence[Tool | ToolSchema] = []) -> int: ...

    @property
    def capabilities(self) -> ModelCapabilities: ...

)
self.kwargs = kwargs

self.model_capabilities = ModelCapabilities(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model capabilities need to be set from input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants