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

Ollama - Standardize meta #1305

Open
saikanov opened this issue Jan 20, 2025 · 4 comments
Open

Ollama - Standardize meta #1305

saikanov opened this issue Jan 20, 2025 · 4 comments
Labels
contributions wanted! Looking for external contributions good first issue Good for newcomers integration:ollama P3

Comments

@saikanov
Copy link

saikanov commented Jan 20, 2025

Is your feature request related to a problem? Please describe.
No, its for enhancement for already working thing

Describe the solution you'd like
So i want to request if possible to make the output of Every Generator is Standardize to one Ouput type

I was working with OpenAI Generator all the time, and i want to use Ollama Generator now, the problem is the Ouput type is different and made an error on metadata output (response already good).

Thanks!

@anakin87 anakin87 changed the title Standardize Output Type Ollama - Standardize meta Jan 20, 2025
@anakin87 anakin87 transferred this issue from deepset-ai/haystack Jan 20, 2025
@anakin87
Copy link
Member

Hello!
In general, we try to be consistent, but some components (including Ollama generators) have not been adapted.

Please explain better what the problem is... Is related to the usage key in meta?

@saikanov
Copy link
Author

Hello! In general, we try to be consistent, but some components (including Ollama generators) have not been adapted.

Please explain better what the problem is... Is related to the usage key in meta?

Exactly! its the usage key in meta that raise me an error. well its just a minor error, but it could be good to be Standardize.

Thanks for your quick response!

@anakin87
Copy link
Member

In short, we should do something like the following, both for OllamaGenerator and OllamaChatGenerator:

# adapt usage metadata to OpenAI format
if usage_metadata := metadata.get("usage_metadata"):
candidate_metadata["usage"] = {
"prompt_tokens": usage_metadata["prompt_token_count"],
"completion_tokens": usage_metadata["candidates_token_count"],
"total_tokens": usage_metadata["total_token_count"],
}

@anakin87 anakin87 added good first issue Good for newcomers contributions wanted! Looking for external contributions labels Jan 24, 2025
@lbux
Copy link
Contributor

lbux commented Jan 31, 2025

Ugh. I can take this over, but it won't be pretty. Unfortunately, switching to the Ollama Python library might have been a "regression" because we have effectively locked ourselves out of having 1:1 parity with OpenAI response objects. The best we would be able to do using Ollama's API is:

{
  "_role": "assistant",
  "_meta": {
    "usage": {
      "completion_tokens": 8,
      "prompt_tokens": 32,
      "total_tokens": null,                 # completion_tokens +  prompt_tokens might work ?
      "completion_tokens_details": null,
      "prompt_tokens_details": null
    },
    "model": "llama3.2:3b",
    "created_at": "2025-01-31T02:11:33.858103105Z",
    "done": true,
    "done_reason": "stop",                  # rename to finish_reason ?
    "total_duration": 279432961,
    "load_duration": 10745144,
    "prompt_eval_duration": 1000000,
    "eval_duration": 266000000
  },
  "_name": null,
  "_content": [
    {
      "text": "1 + 1 = 2"
    }
  ]
}

compared to OpenAI API's response:

{
  "_role": "assistant",
  "_meta": {
    "model": "llama3.2:3b",
    "index": 0,
    "finish_reason": "stop",
    "usage": {
      "completion_tokens": 8,
      "prompt_tokens": 32,
      "total_tokens": 40,
      "completion_tokens_details": null,
      "prompt_tokens_details": null
    }
  },
  "_name": null,
  "_content": [
    {
      "text": "1 + 1 = 2"
    }
  ]
}

But then again at this point we start diverging from the "Ollama API" and some users might expect the Ollama API.

Let me know what you think the best path forward is and I can make a PR @anakin87.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions wanted! Looking for external contributions good first issue Good for newcomers integration:ollama P3
Projects
Development

No branches or pull requests

4 participants