You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The response provided by chatgpt seems to be that go openai does not have this method
import (
"net/http"
"github.com/sashabaranov/go-openai"
"github.com/gin-gonic/gin"
)
// Initialize OpenAI API client
client := openai.NewCompletionAPI("YOUR_API_KEY")
// Define HTTP endpoint to cancel a stream
func cancelStream(c *gin.Context) {
// Extract stream ID from request data
var json struct {
StreamID string json:"stream_id" binding:"required"
}
if err := c.ShouldBindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
// Call OpenAI API to cancel stream
_, err := client.CancelStream(json.StreamID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
// Return success response
c.JSON(http.StatusOK, gin.H{"status": "success"})
}
// Start Gin HTTP server and register endpoint
r := gin.Default()
r.POST("/cancel_stream", cancelStream)
r.Run(":8080")
The text was updated successfully, but these errors were encountered:
package main
import (
"context"
"errors"
"fmt"
"io"
openai "github.com/sashabaranov/go-openai"
)
func main() {
c := openai.NewClient("your token")
ctx := context.Background()
}
// The response provided by chatgpt seems to be that go openai does not have this method
import (
"net/http"
"github.com/sashabaranov/go-openai"
"github.com/gin-gonic/gin"
)
// Initialize OpenAI API client
client := openai.NewCompletionAPI("YOUR_API_KEY")
// Define HTTP endpoint to cancel a stream
func cancelStream(c *gin.Context) {
// Extract stream ID from request data
var json struct {
StreamID string
json:"stream_id" binding:"required"
}
if err := c.ShouldBindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
}
// Start Gin HTTP server and register endpoint
r := gin.Default()
r.POST("/cancel_stream", cancelStream)
r.Run(":8080")
The text was updated successfully, but these errors were encountered: