Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Cody Gateway embeddings: powering with generated metadata - take 2#63112

Merged
janhartman merged 11 commits into
mainfrom
revert-63098-revert-63000-jan/cg-embeddings-metadata-gen
Jun 7, 2024
Merged

Cody Gateway embeddings: powering with generated metadata - take 2#63112
janhartman merged 11 commits into
mainfrom
revert-63098-revert-63000-jan/cg-embeddings-metadata-gen

Conversation

@janhartman

@janhartman janhartman commented Jun 5, 2024

Copy link
Copy Markdown
Contributor

Reverts sourcegraph/sourcegraph#63098 and fixes the problems with conf loading and Fireworks API responses.

Test plan

Try running locally and then with feature flag.

@cla-bot cla-bot Bot added the cla-signed label Jun 5, 2024
// The /completion endpoint returns a text field ...
completion = response.Choices[0].Text
} else if response.Choices[0].Delta != nil {
} else if response.Choices[0].Message != nil {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the key part - according to the api docs, we need to access the message field in the non-streaming case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good to know. But if that's subtle and very important, consider adding a comment in the code to say just that. (So that the next person stumbling across the code has a hint as to why this needs to be Message instead of Delta.

Choices []struct {
Text string `json:"text"`
Text string `json:"text"`
Message *struct {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By adding this here, we now support streaming and non-streaming with the same struct. I suppose it could be a bit cleaner if we were to separate this into two.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would strongly suggest we separate these two. Since otherwise it's confusing as to what data should/should not be present. (e.g. if you have type fireworksResponse, it isn't clear what is required for it to be well formed.

It also makes maintaining the API surface area easier, since things are more explicit. (Even at the cost of having two types that are nearly identical, just one being called fireworksStreamingResponse or something.

@janhartman janhartman requested a review from rafax June 5, 2024 21:57
@rafax rafax requested a review from a team June 6, 2024 13:11

@rafax rafax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, adding @sourcegraph/cody-prime for the Fireworks client change

@chrsmith chrsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall things look good to me, modulo some minor cleanups and nit picks.

Comment thread cmd/cody-gateway/internal/httpapi/embeddings/metadata.go Outdated
Speaker: "user",
Text: promptText,
}},
MaxTokensToSample: 2000,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume this is what you want, but all of our completion endpoints receive the "max tokens to sample" as a parameter. So if we are "standardizing" completions having a specific LLM model, token count, etc. then perhaps we should move this out into a dedicated function?

e.g. func buildCompletionRequestParams(promptText string) types.CompletionRequestParams?

It just seems like we are hard coding some things here that might better be suited for being package level, e.g. const maxTokensToSample = 2000 or having this isolated to a dedicated function. (Rather than having these all be fixed in generateMetadataForChunk.)

Does that make sense? This isn't a major issue, just a minor code smell. So if none of this resonates with you feel free to ignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I understand your concern. However, this is purely experimental for now so I'll leave it as is. If this ends up working well we will likely revisit and refactor this module anyway, otherwise it's going to be deleted soon.

Comment thread cmd/cody-gateway/shared/config/config.go Outdated
Comment thread internal/codygateway/types.go
// The /completion endpoint returns a text field ...
completion = response.Choices[0].Text
} else if response.Choices[0].Delta != nil {
} else if response.Choices[0].Message != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good to know. But if that's subtle and very important, consider adding a comment in the code to say just that. (So that the next person stumbling across the code has a hint as to why this needs to be Message instead of Delta.

Choices []struct {
Text string `json:"text"`
Text string `json:"text"`
Message *struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would strongly suggest we separate these two. Since otherwise it's confusing as to what data should/should not be present. (e.g. if you have type fireworksResponse, it isn't clear what is required for it to be well formed.

It also makes maintaining the API surface area easier, since things are more explicit. (Even at the cost of having two types that are nearly identical, just one being called fireworksStreamingResponse or something.

@janhartman

Copy link
Copy Markdown
Contributor Author

Thanks for the review @chrsmith, great points! I'll be merging this as is now so I can start dogfooding it and then revisit it when I have some experiment results.

@janhartman janhartman merged commit 18bdafa into main Jun 7, 2024
@janhartman janhartman deleted the revert-63098-revert-63000-jan/cg-embeddings-metadata-gen branch June 7, 2024 10:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants