Skip to content
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 AI Client wrapper for GoFr #1242

Open
coolwednesday opened this issue Nov 26, 2024 · 12 comments
Open

Open AI Client wrapper for GoFr #1242

coolwednesday opened this issue Nov 26, 2024 · 12 comments
Assignees

Comments

@coolwednesday
Copy link
Contributor

No description provided.

@yash-sojitra
Copy link

Hi, can you assign me this issue.

Also i want to clear out a doubt that whether to build this in a separate folder at pkg/gofr or at pkg/gofr/services.

(new to OpenSource and first issue. so...)

@vikash
Copy link
Contributor

vikash commented Dec 16, 2024

pkg/gofr/service/openAI might be a good place, IMO. But, it should be written in such a way that it gets included only on demand and does not affect all the other people's binary who don't need it. (Ref: datasources)

@yash-sojitra
Copy link

yash-sojitra commented Dec 18, 2024

I have another doubt. i found that OpenAI has also developed it's wrapper so will it be okay to use that package and will add other logger and metrics functionalities along with it while implementing it. I think it's just like using a mongo client package and wrapping it with logger, metrics and tracer.

link to openai-go package

@yash-sojitra
Copy link

also there is a question for @coolwednesday , i want to clarify that for OpenAI do i need to implement all of the endpoints or just the normal chat one.

{78AF9FFB-3294-4439-A239-DB16A9C49C42}

@coolwednesday
Copy link
Contributor Author

I have another doubt. i found that OpenAI has also developed it's wrapper so will it be okay to use that package and will add other logger and metrics functionalities along with it while implementing it. I think it's just like using a mongo client package and wrapping it with logger, metrics and tracer.

link to openai-go package

You can go ahead and build a wrapper around it.

@yash-sojitra
Copy link

@coolwednesday And for the last doubt? I think it would be enough to cover main endpoints like chat, image, audio, files, etc.

@coolwednesday
Copy link
Contributor Author

also there is a question for @coolwednesday , i want to clarify that for OpenAI do i need to implement all of the endpoints or just the normal chat one.

{78AF9FFB-3294-4439-A239-DB16A9C49C42}

I think we can skip audio, images ..... Can you brief me on what do the models and moderation endpoints do ?

@yash-sojitra
Copy link

Models is used to list and describe various models available in the api

Moderations is used to classify if any given input content is harmful across several categories. Basically monitoring requests so can be tracked using request id. (can be used to log requests but increases api call).

@coolwednesday
Copy link
Contributor Author

coolwednesday commented Dec 18, 2024

Models is used to list and describe various models available in the api

Moderations is used to classify if any given input content is harmful across several categories. Basically monitoring requests so can be tracked using request id. (can be used to log requests but increases api call).

I want to use this feature to integrate AI with the observability, that GoFr provides. For this, we’ll likely need features like chat, embedding conversion, fine-tuning, batch processing, models, and moderation. We can skip audio and image-related features for now.

You don't need to implement all the endpoints that I discussed. Let’s start small and explore how these features depend on each other. Try to implement a few related ones together in a single pull request (PR).

@yash-sojitra
Copy link

yash-sojitra commented Dec 20, 2024

@coolwednesday @vikash i have wrapped chat endpoint and now will be writing tests, but before that i wanted to know about mock files that different datasources have implemented like mock_logger.go and mock_metrics.go so i wanted to know why they are used.

@coolwednesday
Copy link
Contributor Author

@coolwednesday @vikash i have wrapped chat endpoint and now will be writing tests, but before that i wanted to know about mock files that different datasources have implemented like mock_logger.go and mock_metrics.go so i wanted to know why they are used.

These mock files exist because the datasource clients incorporate observability features—traces, metrics, and logs—into each of their methods. When writing tests, we not only mock the underlying methods being called but also need to set up mock expectations for logger, metrics.

To achieve this, the respective interfaces for these observability components (e.g., logger and metrics) are defined, and their mock implementations are created. This is where files like mock_logger.go and mock_metrics.go come into play.

The reason for this setup is that, in GoFr, datasource clients are assigned the original GoFr app's logger, metrics, and traces only when the user specifies the necessary configs and calls the addDatasource method on the app. This can be seen in the external_db.go file.

For the chat client, a similar approach will be required: define interfaces for logger and metrics (traces, if invoked without initialization, do not cause a panic), create their corresponding mocks, and set them up correctly during testing.

@yash-sojitra
Copy link

yash-sojitra commented Dec 22, 2024

@coolwednesday I completed implementing the chat endpoint but , getting a linter error and i am pretty much sure it's bug it gives that an imported package is not formatted.

{26CB8BBB-C8E8-480B-8CE7-DF72D0DAD32D}

Error:

  • File is not gofmt-ed with -s (gofmt)go-golangci-lint

I am only getting this error in certain files even i have formatted all of them equal

{98E13196-9E2F-4CDA-8AE4-CB8A73DB6CAD}

(orange ones are the one with this linter error)

I searched this error but got no fruitful result

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

No branches or pull requests

3 participants