-
Notifications
You must be signed in to change notification settings - Fork 0
add model mapping for embeddings #21
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
base: defang
Are you sure you want to change the base?
Conversation
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.
small suggestions inline, but largely 👍
@@ -82,7 +47,7 @@ def get_proxy_target(model, path): | |||
else: | |||
return f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/{model}:rawPredict" | |||
|
|||
def get_headers(model, request, path): | |||
def get_header(model, request, path): |
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.
def get_header(model, request, path): | |
def get_headers(model, request, path): |
@@ -159,7 +127,7 @@ async def handle_proxy(request: Request, path: str): | |||
conversion_target = "anthropic" | |||
|
|||
# Build safe target URL | |||
target_url, request_headers = get_headers(model, request, path) | |||
target_url, request_headers = get_header(model, request, path) |
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.
target_url, request_headers = get_header(model, request, path) | |
target_url, request_headers = get_headers(model, request, path) |
vertex_request = { | ||
"instances": [] | ||
} | ||
|
||
msg_input = request.get("input") | ||
if type(msg_input) is str: | ||
vertex_request["instances"] = [{ | ||
"content": f"{msg_input}" | ||
}] | ||
elif type(msg_input) is list: | ||
vertex_request["instances"] = [{"content": f"{str(item)}"} for item in msg_input] | ||
|
||
return vertex_request |
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.
I think we can tighten this up a bit. What do you think of this?
vertex_request = { | |
"instances": [] | |
} | |
msg_input = request.get("input") | |
if type(msg_input) is str: | |
vertex_request["instances"] = [{ | |
"content": f"{msg_input}" | |
}] | |
elif type(msg_input) is list: | |
vertex_request["instances"] = [{"content": f"{str(item)}"} for item in msg_input] | |
return vertex_request | |
inputs = request.get("input", []) | |
if not isinstance(inputs, list): | |
inputs = [inputs] | |
return { | |
"instances": [{"content": str(content)} for content in inputs] | |
} |
Description of changes:
Add GCP embeddings. Converts OpenAI embeddings request to a vertex embeddings to make call to model. Response is conversely converted from vertex response to OpenAI embeddings response.
The previous vertex.py was changed to chat.py (parallels how AWS does it). Minimal changes to AWS code to ensure we don't have major issues taking upstream changes.