This repository contains a SvelteKit application that integrates OpenAI's GPT with GraphQL to provide an interactive assistant experience. Users can ask questions about a GraphQL schema, and the assistant will provide responses.
- GraphQL Integration: Communicates with a GraphQL API to fetch and display data based on user queries.
- OpenAI Assistant: Leverages OpenAI's API to understand and respond to user queries.
- Interactive UI: Provides a chat-like interface for users to interact with the GraphQL assistant.
- Node.js and npm installed.
- An OpenAI API key.
- Clone the repository:
git clone https://github.com/kasperlaursen/openai-assistant-gql-demo.git
- Navigate to the project directory:
cd openai-assistant-gql-demo
- Install dependencies:
npm install
- Create a
.env
file at the root of your project and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
To configure your assistant with the specific capabilities required for interacting with the Star Wars GraphQL API, follow these steps:
-
Download the GraphQL Schema: Download the full GraphQL schema from the following Apollo Studio link: Star Wars SWAPI GraphQL Schema.
-
Configure the Assistant: Set up your assistant with the instructions provided.
You are an helpful assistant with knowledge about the Star Wars GraphQL api and its full schema.
You will help the user gain information about the schema, as well as generating queries for the graphql endpoint based on the schema.
The full GraphQL schema is star-wars-swapi.graphql.
-
Update the Assistant ID: In your code, ensure you have the correct
ASSISTANT_ID
set to link to your configured OpenAI assistant. This ID connects your code with the specific assistant instance trained for this task. -
Upload the GraphQL Schema: Upload the
star-wars-swapi.graphql
schema file to your application's environment where the assistant can access it. -
Configure Tool Functions: Utilize the
callWithQuery
function as a bridge between your assistant and the GraphQL API. This function should be defined to accept aquery
parameter, representing the GraphQL query to be executed against the Star Wars API.
Here's the JSON schema for the callWithQuery
function for your reference:
{
"name": "callWithQuery",
"description": "Sends a GraphQL Query request to the api, and returns the result.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The graphql query to execute"
}
},
"required": ["query"]
}
}
- Integrate with Code Interpreter and Retrieval Tools: Make sure your setup includes a code interpreter for the dynamic execution of the code snippets and a retrieval mechanism to fetch information based on user requests.
After completing these steps, your assistant should be ready to help users explore the Star Wars GraphQL schema efficiently.
Start the development server:
npm run dev
Visit http://localhost:3000
in your browser to view the application.
- Type your questions about the GraphQL schema into the input field.
- Press 'Send' to submit your question.
- View the assistant's response in the chat interface.
Contributions are welcome! Please feel free to submit a pull request.
Ui by: v0.dev