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

xef-dashboard basic API #372

Merged
merged 6 commits into from
Sep 1, 2023
Merged

xef-dashboard basic API #372

merged 6 commits into from
Sep 1, 2023

Conversation

calvellido
Copy link
Contributor

Description

This PR adds the needed code to be able to connect with xef-server API and communicate with it though a generic form. Currently, it uses the chat/completions endpoint. In order to use this in the best way, the request body and response have been types following the OpenAI documentation:

https://github.com/openai/openai-node/

To be able to properly exchange data with the API, the changes also add a Settings page, where the user can save its xef-server/OpenAI API key to communicate with the server.

It also modifies Ktor config to allow CORS auth, as it previously wouldn't work through the combination of CORS and the Authorization header.

Preview

imagen
imagen

Copy link
Contributor

@javipacheco javipacheco left a comment

Choose a reason for hiding this comment

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

I have been trying the code locally and I have a problem

When I create the website using npm run dev the page works as expected, but if I create the website using ./gradlew web when I send a message I always receive this message Chat completions request couldn't be completed, is the API key set?. I'm saving the API key in the settings

On the other hand, if I reload the page in the browser I have to save the API Key again. I understand what the problem is, but should we store the key somewhere?

@calvellido
Copy link
Contributor Author

calvellido commented Sep 1, 2023

I have been trying the code locally and I have a problem

When I create the website using npm run dev the page works as expected, but if I create the website using ./gradlew web when I send a message I always receive this message Chat completions request couldn't be completed, is the API key set?. I'm saving the API key in the settings

On the other hand, if I reload the page in the browser I have to save the API Key again. I understand what the problem is, but should we store the key somewhere?

Everything works as expected on my end.

Is the server working OK if you request through curl or Postman? Open the app browser's dev console and check the console (the specific error is surely printed there) and the requests tab, if you are having a 401, a 500… Please also check the server logs to see if the request is reaching the server, and something is going up there, even is the response isn't showing it.

Regarding the API key: of course, ideally, the API key, along the rest of settings, could be saved in the localStorage or sessionStorage to have it persist in or in between browser sessions. Next PRs could address this.

There's probably room to improve in all components, but the PR scope should be set somewhere, otherwise the code might get cut without being finished. For example, in this one, initially the API key was set per request, but I thought this could be a good opportunity to see the difference between local state (questions and its responses) and context (settings data) in proper code.

Copy link
Contributor

@javipacheco javipacheco left a comment

Choose a reason for hiding this comment

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

🚀 LGTM!

I was opening the web from http://0.0.0.0:8080 and this is not working because is blocked by CORS policy. Finally using http://localhost:8080 is working as expected

@calvellido calvellido merged commit 3105b29 into main Sep 1, 2023
5 checks passed
@calvellido calvellido deleted the calvellido-basic-api branch September 1, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants