I tried the same approach, but it didn’t work. I should mention that I’m completely new to coding. I have a question: When I build an Assistant in the Playground and upload some files, those files are stored in a vector store, and I receive an ID for that vector store. If I then send a request to my Assistant using its ID, will it automatically access the data in the vector store to provide the correct response?
Additionally, what about the prompt I set up for the Assistant? Does it play any role when I send an API request?
Lastly, how can I actually access the Assistant? I’ve created a project, an Assistant, and an API for the project. I’ve also added all the IDs to my .env
file. However, I keep getting error messages like:
Error in the request to OpenAI: OpenAI API Error: Unrecognized request arguments supplied: assistant_id, vector_store_id
Error in the request to OpenAI: OpenAI API Error: Invalid URL (POST /v1/assistants/asst_nY7siE1iEtnXA8PtkZRWTflR/messages)
Error from OpenAI: Unknown parameter: 'assistant_id'.
These errors vary depending on how I try to access the Assistant.
This is my last version:
// Log-Ausgabe zum ĂśberprĂĽfen des Serverstarts
console.log(“Server startet…”);
// Import der benötigten Module
import express from “express”;
import bodyParser from “body-parser”;
import fetch from “node-fetch”;
import dotenv from “dotenv”;
import cors from “cors”;
// Laden der Umgebungsvariablen
dotenv.config();
// Initialisieren der Express-App
const app = express();
console.log(“Express-App initialisiert.”);
// Middleware-Konfiguration
app.use(express.static(“public”)); // Statische Dateien bereitstellen
app.use(bodyParser.json()); // JSON-Parsing
app.use(cors()); // CORS aktivieren
// POST-Endpunkt fĂĽr Chat-Anfragen
app.post(“/chat”, async (req, res) => {
const userMessage = req.body.message;
if (!userMessage) {
return res.status(400).json({ error: “Nachricht fehlt im Request-Body.” });
}
try {
// Anfrage an den Assistants-v2-Endpunkt mit Vector Store und Organisation
const response = await fetch(
https://api.openai.com/v2/assistants/${process.env.ASSISTANT_ID}/messages
,
{
method: “POST”,
headers: {
“Content-Type”: “application/json”,
Authorization: Bearer ${process.env.OPENAI_API_KEY}
,
“OpenAI-Organization”: process.env.OPENAI_ORGANIZATION_ID, // Organisation hinzufügen
},
body: JSON.stringify({
message: {
role: “user”,
content: userMessage, // Nachricht des Nutzers
},
vector_store_id: process.env.VECTOR_STORE_ID, // Vector Store einbinden
}),
}
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(
`OpenAI-API-Fehler: ${errorData.error?.message || "Unbekannter Fehler"}`
);
}
const data = await response.json();
res.json({ reply: data.message.content });
} catch (error) {
console.error(“Fehler bei der Anfrage an OpenAI:”, error.message);
res.status(500).json({ error: "Serverfehler: " + error.message });
}
});
// Definieren des Ports und Starten des Servers
const PORT = process.env.PORT || 3000;
console.log(“Starte Server…”);
try {
app.listen(PORT, () => {
console.log(Server läuft auf http://localhost:${PORT}
);
}).on(“error”, (err) => {
console.error(“Server konnte nicht gestartet werden:”, err.message);
});
} catch (err) {
console.error(“Fehler beim Starten des Servers:”, err.message);
}
// Globale Fehlerbehandlung
process.on(“uncaughtException”, (err) => {
console.error(“Ungefangene Ausnahme:”, err.message);
});
process.on(“unhandledRejection”, (reason) => {
console.error(“Unbehandelte Promise-Ablehnung:”, reason);
});
Error: Fehler bei der Anfrage an OpenAI: OpenAI-API-Fehler: Unknown request URL: POST /v2/assistants/asst_nY7siE1iEtnXA8PtkZRWTflR/messages. Please check the URL for typos, or see the docs at https://platform.openai.com/docs/api-reference/.
One last question: Will the Assistant feature be deprecated in the future, or will it remain available?