Skip to content

Commit

Permalink
Merge pull request #41 from coinbase/alissa.crane/fixes
Browse files Browse the repository at this point in the history
chore: update conversation id
  • Loading branch information
abcrane123 authored Nov 9, 2024
2 parents 4d65ff5 + 58c6f31 commit 0679f54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 2 additions & 6 deletions app/components/Stream.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { cn } from '@coinbase/onchainkit/theme';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useTransactionCount } from 'wagmi';
import { AGENT_WALLET_ADDRESS, DEFAULT_PROMPT } from '../constants';
import useChat from '../hooks/useChat';
import type { AgentMessage, StreamEntry } from '../types';
import { generateUUID, markdownToPlainText } from '../utils';
import { markdownToPlainText } from '../utils';
import StreamItem from './StreamItem';

type StreamProps = {
Expand All @@ -16,9 +16,6 @@ export default function Stream({ className }: StreamProps) {
const [isThinking, setIsThinking] = useState(true);
const [loadingDots, setLoadingDots] = useState('');
const bottomRef = useRef<HTMLDivElement>(null);
const conversationId = useMemo(() => {
return generateUUID();
}, []);

const handleSuccess = useCallback((messages: AgentMessage[]) => {
let message = messages.find((res) => res.event === 'agent');
Expand All @@ -42,7 +39,6 @@ export default function Stream({ className }: StreamProps) {

const { postChat, isLoading } = useChat({
onSuccess: handleSuccess,
conversationId,
});

// enables live stream of agent thoughts
Expand Down
6 changes: 5 additions & 1 deletion app/hooks/useChat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useState } from 'react';
import { API_URL } from '../config';
import type { AgentMessage } from '../types';
import { generateUUID } from '../utils';

type UseChatResponse = {
messages?: AgentMessage[];
Expand Down Expand Up @@ -30,7 +31,10 @@ export default function useChat({
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ input, conversation_id: conversationId }),
body: JSON.stringify({
input,
conversation_id: conversationId || generateUUID(),
}),
});

if (!response.ok) {
Expand Down

0 comments on commit 0679f54

Please sign in to comment.