Skip to content

Commit

Permalink
Add support for OpenAI Assistant API (#148)
Browse files Browse the repository at this point in the history
* Assistant API

* Option to edit assistant
  • Loading branch information
Ashesh3 authored Nov 20, 2023
1 parent 62c1cb3 commit a15858b
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 54 deletions.
20 changes: 16 additions & 4 deletions src/app/(main)/project/[project_id]/chat/[chat_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export default function Chat(params: {
refetchOnWindowFocus: false,
}
);

const projectQuery = useQuery(
["chat", project_id],
() => API.projects.get(project_id),
{
refetchOnWindowFocus: false,
}
);
const project: Project | undefined = projectQuery.data;

const chat: Chat | undefined = chatQuery.data;
const [projectData, setProjectData] = useState<Project>();

Expand Down Expand Up @@ -85,13 +95,15 @@ export default function Chat(params: {
params.formdata,
openai_key,
streamChatMessage,
20
20,
!project?.assistant_id
),
{
retry: false,
// onSuccess: async (data, vars) => {
// await chatQuery.refetch();
// }
onSuccess: async (data, vars) => {
if(!project?.assistant_id)
await chatQuery.refetch();
},
onError: async (error, vars) => {
converseMutation.error = error
setIsTyping(false);
Expand Down
37 changes: 21 additions & 16 deletions src/app/(main)/project/[project_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ export default function Chat(params: { params: { project_id: string } }) {
params.formdata,
openai_key,
streamChatMessage,
20
20,
!project?.assistant_id
),
{
retry: false,
onSuccess: async (data, vars) => {
setChatID(data.external_id);
await queryClient.invalidateQueries(["chats"]);
setIsTyping(false);
},
}
);
Expand Down Expand Up @@ -132,21 +135,23 @@ export default function Chat(params: { params: { project_id: string } }) {
<>
<h2 className="font-semibold mt-8">Try asking me -</h2>
<div className="grid md:grid-cols-2 mt-4 gap-4 px-4 lg:max-w-4xl mx-auto">
{(project?.display_preset_questions ?? []).map((prompt, i) => (
<button
onClick={async () => {
setChat(prompt);
setIsTyping(true);
const fd = await getFormData(undefined, prompt);
newChatMutation.mutate({ formdata: fd });
}}
disabled={newChatMutation.isLoading}
className="bg-white hover:shadow-lg hover:bg-gray-100 hover:text-indigo-500 text-left border border-gray-200 rounded-lg p-4 transition disabled:opacity-50 disabled:hover:text-gray-400"
key={i}
>
{prompt}
</button>
))}
{(project?.display_preset_questions ?? []).map(
(prompt, i) => (
<button
onClick={async () => {
setChat(prompt);
setIsTyping(true);
const fd = await getFormData(undefined, prompt);
newChatMutation.mutate({ formdata: fd });
}}
disabled={newChatMutation.isLoading}
className="bg-white hover:shadow-lg hover:bg-gray-100 hover:text-indigo-500 text-left border border-gray-200 rounded-lg p-4 transition disabled:opacity-50 disabled:hover:text-gray-400"
key={i}
>
{prompt}
</button>
)
)}
</div>
</>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin/tests/[testsuite_id]/runs/[testrun_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ export default function Page({ params }: { params: { testsuite_id: string, testr
{document.title}
</div>
</div>
<div className="w-1/2">
<img src={document.file.split("?")[0] + '?r=' + Math.floor(Math.random() * 100000)} alt="File" className="w-full" crossOrigin="anonymous" />
<div className="w-1/2 h-1/2">
<img src={document.file.split("?")[0] + '?r=' + Math.floor(Math.random() * 100000)} alt="File" crossOrigin="anonymous" />
</div>
</Link>
</div>
Expand Down
Loading

1 comment on commit a15858b

@vercel
Copy link

@vercel vercel bot commented on a15858b Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.