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

Merged
0 commits merged into from
Nov 25, 2024
Merged

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.

@colombod colombod closed this pull request by merging all changes into microsoft:main in d186a41 Nov 25, 2024
@husseinmozannar
Copy link
Contributor

What is happening? Why are there no commits and why was this PR closed?

@colombod
Copy link
Collaborator

i don't understand I am sure i did not but logs here says different

@ekzhu
Copy link
Collaborator

ekzhu commented Nov 25, 2024

@MervinPraison I think you might want to create a new branch on your repo, and create a PR from there.

BTW can you also address the comments first?

@colombod
Copy link
Collaborator

But how did this one got merged by me, this is the one I merged : #4329

@husseinmozannar
Copy link
Contributor

husseinmozannar commented Nov 25, 2024

I think the issue is that @MervinPraison needs to create a branch first on their fork of autogen, then create a PR comparing that branch to microsoft:main. It must be some weird behavior from GitHub that got this closed @colombod

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.

4 participants