Skip to content

Commit

Permalink
Merge pull request #46 from nowscott/development
Browse files Browse the repository at this point in the history
add:添加部分调试信息
  • Loading branch information
nowscott authored Jul 22, 2024
2 parents b9dc4cb + f8b55ca commit 08d02ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pages/ChatPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/pages/ChatPage.js
import React, { useState, useCallback, useEffect } from 'react';
import React, { useState, useCallback} from 'react';
import ChatAPI from 'components/ChatAPI';
import NavBar from 'components/layout/NavBar';
import MessageList from 'components/layout/MessageList';
Expand Down
4 changes: 3 additions & 1 deletion src/service/groq.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function sendGroqMessage({

const fetchChatCompletion = async () => {
try {
console.log(model,'API 请求中...');
const chatCompletion = await groq.chat.completions.create({
messages: [
{ role: 'system', content: systemPrompt },
Expand All @@ -41,15 +42,16 @@ export function sendGroqMessage({

for await (const chunk of chatCompletion) {
const content = chunk.choices[0]?.delta?.content || '';
// console.log('content', content);
buffer += content;
onContentUpdate(buffer);
buffer = '';
if (chunk.x_groq && chunk.x_groq.usage) {
onTokenUpdate(chunk.x_groq.usage.total_tokens);
}
}

onCompletion();
console.log(model,'API 请求成功');
} catch (error) {
console.error('API 请求失败:', error);
onCompletion({ error: '请求失败,请稍后重试。' });
Expand Down

0 comments on commit 08d02ab

Please sign in to comment.