Skip to content

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

Open
wants to merge 6 commits into
base: defang
Choose a base branch
from
Open

Conversation

nullfunc
Copy link

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.

@nullfunc nullfunc deployed to AWS_ROLE_TO_ASSUME June 11, 2025 00:40 — with GitHub Actions Active
Copy link
Member

@jordanstephens jordanstephens left a 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_url, request_headers = get_header(model, request, path)
target_url, request_headers = get_headers(model, request, path)

Comment on lines +46 to +58
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
Copy link
Member

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?

Suggested change
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]
}

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.

2 participants