-
Notifications
You must be signed in to change notification settings - Fork 76
Pass down base URL and API key to completion handler #1002
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bbe3d79
Pass down base URL and API key to completion handler
JAORMX 9b44f5e
fix unit tests and formatting
aponcedeleonch 05ba85b
fix integration tests
aponcedeleonch d5281d2
Pass API key to ollama calls
JAORMX 3769547
Handle optional authorization header in ollama endpoints.
JAORMX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,17 +82,25 @@ async def ollama_stream_generator( # noqa: C901 | |
|
||
class OllamaShim(BaseCompletionHandler): | ||
|
||
def __init__(self, base_url): | ||
self.client = AsyncClient(host=base_url, timeout=30) | ||
|
||
async def execute_completion( | ||
self, | ||
request: ChatCompletionRequest, | ||
base_url: Optional[str], | ||
api_key: Optional[str], | ||
stream: bool = False, | ||
is_fim_request: bool = False, | ||
) -> Union[ChatResponse, GenerateResponse]: | ||
"""Stream response directly from Ollama API.""" | ||
if not base_url: | ||
raise ValueError("base_url is required for Ollama") | ||
|
||
# TODO: Add CodeGate user agent. | ||
headers = dict() | ||
if api_key: | ||
headers["Authorization"] = f"Bearer {api_key}" | ||
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. Does the bearer token get forwarded or does it have some other meaning later on? 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. It gets set so we can forward it |
||
|
||
client = AsyncClient(host=base_url, timeout=300, headers=headers) | ||
|
||
try: | ||
if is_fim_request: | ||
prompt = "" | ||
|
@@ -103,7 +111,7 @@ async def execute_completion( | |
if not prompt: | ||
raise ValueError("No user message found in FIM request") | ||
|
||
response = await self.client.generate( | ||
response = await client.generate( | ||
model=request["model"], | ||
prompt=prompt, | ||
raw=request.get("raw", False), | ||
|
@@ -112,7 +120,7 @@ async def execute_completion( | |
options=request["options"], # type: ignore | ||
) | ||
else: | ||
response = await self.client.chat( | ||
response = await client.chat( | ||
model=request["model"], | ||
messages=request["messages"], | ||
stream=stream, # type: ignore | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
could we default to
localhost:11434
?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.
We should already get this default frm the caller.