-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Add helm to core #578
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
Changes from 4 commits
c572e27
2de364b
8ebd9a7
9d0d96e
b4088be
b670697
bfe039d
6bc4f6a
96adcfb
c06c28d
edd681f
02b0109
a91e83e
326c418
92602aa
f2d0909
97465f1
73662b8
90d96aa
3a88b94
11442df
1dfb0dd
4c4723b
846c45e
2c0bfc8
62d2d76
57630ee
0516d6e
bacfb01
6e17fdf
a9f8ab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,14 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sys import api_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic import BaseModel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import instructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from cognee.infrastructure.llm.llm_interface import LLMInterface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from cognee.infrastructure.llm.config import get_llm_config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from openai import OpenAI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import base64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class OllamaAPIAdapter(LLMInterface): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Adapter for a Ollama API LLM provider using instructor with an OpenAI backend.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -17,21 +15,13 @@ class OllamaAPIAdapter(LLMInterface): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MAX_RETRIES = 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endpoint: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max_tokens: int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_version: str = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self, endpoint: str, api_key: str, model: str, name: str, max_tokens: int, api_version: str = None) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.name = name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.model = model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.api_key = api_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.endpoint = endpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.max_tokens = max_tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.api_version = api_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.api_version= api_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.aclient = instructor.from_openai( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OpenAI(base_url=self.endpoint, api_key=self.api_key), mode=instructor.Mode.JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -60,52 +50,57 @@ async def acreate_structured_output( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def create_transcript(self, input): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Generate a audio transcript from a user query.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not os.path.isfile(input): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"The file {input} does not exist.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def create_transcript(self, input_file: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Generate an audio transcript from a user query.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # with open(input, 'rb') as audio_file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # audio_data = audio_file.read() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not os.path.isfile(input_file): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"The file {input_file} does not exist.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| transcription = self.aclient.transcription( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model=self.transcription_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file=Path(input), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key=self.api_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_base=self.endpoint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_version=self.api_version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max_retries=self.MAX_RETRIES, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with open(input_file, "rb") as audio_file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| transcription = self.aclient.audio.transcriptions.create( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model="whisper-1", # Ensure the correct model for transcription | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file=audio_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| language="en", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ensure the response contains a valid transcript | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not hasattr(transcription, "text"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("Transcription failed. No text returned.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return transcription | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return transcription.text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def transcribe_image(self, input) -> BaseModel: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with open(input, "rb") as image_file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def transcribe_image(self, input_file: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Transcribe content from an image using base64 encoding.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not os.path.isfile(input_file): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"The file {input_file} does not exist.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize missing transcription_model attribute. The Add the following to the constructor: def __init__(self, endpoint: str, api_key: str, model: str, name: str, max_tokens: int, api_version: str = None) -> None:
self.name = name
self.model = model
self.api_key = api_key
self.endpoint = endpoint
self.max_tokens = max_tokens
self.api_version = api_version
+ self.transcription_model = model # or add a new parameter if a different model is needed for transcription📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with open(input_file, "rb") as image_file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoded_image = base64.b64encode(image_file.read()).decode("utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self.aclient.completion( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response = self.aclient.chat.completions.create( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model=self.model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages=[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "role": "user", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "content": [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type": "text", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "text": "What’s in this image?", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {"type": "text", "text": "What’s in this image?"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type": "image_url", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "image_url": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "url": f"data:image/jpeg;base64,{encoded_image}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "image_url": {"url": f"data:image/jpeg;base64,{encoded_image}"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key=self.api_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_base=self.endpoint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_version=self.api_version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max_tokens=300, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max_retries=self.MAX_RETRIES, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ensure response is valid before accessing .choices[0].message.content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not hasattr(response, "choices") or not response.choices: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("Image transcription failed. No response received.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return response.choices[0].message.content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix formatting issue.
Add a space after the equals sign.
📝 Committable suggestion