Skip to content

Commit

Permalink
Update properties.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Feb 2, 2025
1 parent 59287db commit 8d1d71d
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions wap/pkg/wifi/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ type ChatWithAIResponse struct {
Msg string `json:"msg"`
}

type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}

type Payload struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Stream bool `json:"stream"`
}

const (
B = 1
KB = 1024 * B
Expand Down Expand Up @@ -350,17 +361,22 @@ func FetchContainerLogs(ctx context.Context, req FetchContainerLogsRequest) (str
}

func FetchAIResponse(ctx context.Context, aiModel string, userMessage string) (<-chan string, error) {
url := "http://127.0.0.1:8080/get_RKLLM_output"
url := "http://127.0.0.1:8080/rkllm_chat"

payload := map[string]string{
"ai_model": aiModel,
"user_message": userMessage,
// Prepare payload
payload := Payload{
Model: aiModel,
Messages: []Message{
{Role: "user", Content: userMessage},
},
Stream: true,
}
jsonPayload, err := json.Marshal(payload)
if err != nil {
return nil, fmt.Errorf("failed to marshal payload: %v", err)
}

// Create HTTP request
req, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(jsonPayload))
if err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
Expand Down Expand Up @@ -395,7 +411,8 @@ func FetchAIResponse(ctx context.Context, aiModel string, userMessage string) (<
fmt.Printf("Error reading response stream: %v\n", err)
break
}
responseChannel <- line // Send each chunk of data as it arrives
line = line[:len(line)-1] // Remove newline character
responseChannel <- line // Send each chunk of data as it arrives
}
}()

Expand Down

0 comments on commit 8d1d71d

Please sign in to comment.