Merge branch 'main' into fix/remove-duplicated-prompt-template

This commit is contained in:
Zineb El Bachiri 2023-06-14 15:32:54 +02:00 committed by GitHub
commit 97d63b886d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
72 changed files with 81 additions and 71 deletions

View File

@ -1,6 +1,7 @@
from langchain.prompts.prompt import PromptTemplate
prompt_template = """Use the following pieces of context to answer the question in the language of the question. If you don't know the answer, just say that you don't know, don't try to make up an answer.
prompt_template = """Your name is Quivr. You are a second brain. A person will ask you a question and you will provide a helpful answer. Write the answer in the same language as the question. If you don't know the answer, just say that you don't know. Don't try to make up an answer. Use the following context to answer the question:
{context}

View File

@ -2,15 +2,17 @@ import os
from typing import Any, Dict, List
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.question_answering import load_qa_chain
from langchain.chat_models import ChatOpenAI, ChatVertexAI
from langchain.chat_models.anthropic import ChatAnthropic
from langchain.docstore.document import Document
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.llms import VertexAI
from langchain.llms import OpenAI, VertexAI
from langchain.memory import ConversationBufferMemory
from langchain.vectorstores import SupabaseVectorStore
from llm import LANGUAGE_PROMPT
from models.chats import ChatMessage
from supabase import Client, create_client
@ -101,11 +103,11 @@ def get_qa_llm(chat_message: ChatMessage, user_id: str, user_openai_api_key: str
memory = ConversationBufferMemory(
memory_key="chat_history", return_messages=True)
ConversationalRetrievalChain.prompts = LANGUAGE_PROMPT
qa = None
# this overwrites the built-in prompt of the ConversationalRetrievalChain
ConversationalRetrievalChain.prompts = LANGUAGE_PROMPT
if chat_message.model.startswith("gpt"):
qa = ConversationalRetrievalChain.from_llm(
ChatOpenAI(
@ -114,10 +116,12 @@ def get_qa_llm(chat_message: ChatMessage, user_id: str, user_openai_api_key: str
vector_store.as_retriever(), memory=memory, verbose=True,
return_source_documents=with_sources,
max_tokens_limit=1024)
qa.combine_docs_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff", prompt=LANGUAGE_PROMPT.QA_PROMPT)
elif chat_message.model.startswith("vertex"):
qa = ConversationalRetrievalChain.from_llm(
ChatVertexAI(), vector_store.as_retriever(), memory=memory, verbose=False,
ChatVertexAI(), vector_store.as_retriever(), memory=memory, verbose=True,
return_source_documents=with_sources, max_tokens_limit=1024)
qa.combine_docs_chain = load_qa_chain(ChatVertexAI(), chain_type="stuff", prompt=LANGUAGE_PROMPT.QA_PROMPT)
elif anthropic_api_key and chat_message.model.startswith("claude"):
qa = ConversationalRetrievalChain.from_llm(
ChatAnthropic(
@ -125,4 +129,6 @@ def get_qa_llm(chat_message: ChatMessage, user_id: str, user_openai_api_key: str
vector_store.as_retriever(), memory=memory, verbose=False,
return_source_documents=with_sources,
max_tokens_limit=102400)
qa.combine_docs_chain = load_qa_chain(ChatAnthropic(), chain_type="stuff", prompt=LANGUAGE_PROMPT.QA_PROMPT)
return qa

View File

@ -1,4 +1,4 @@
import Button from "@/app/components/ui/Button";
import Button from "@/lib/components/ui/Button";
import { useGoogleLogin } from "./hooks/useGoogleLogin";

View File

@ -1,6 +1,6 @@
"use client";
import Button from "@/app/components/ui/Button";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import { useToast } from "@/lib/hooks/useToast";
import { useState } from "react";

View File

@ -1,10 +1,10 @@
"use client";
import Button from "@/app/components/ui/Button";
import Card from "@/app/components/ui/Card";
import { Divider } from "@/app/components/ui/Divider";
import Field from "@/app/components/ui/Field";
import PageHeading from "@/app/components/ui/PageHeading";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import Card from "@/lib/components/ui/Card";
import { Divider } from "@/lib/components/ui/Divider";
import Field from "@/lib/components/ui/Field";
import PageHeading from "@/lib/components/ui/PageHeading";
import { useToast } from "@/lib/hooks/useToast";
import Link from "next/link";
import { redirect } from "next/navigation";

View File

@ -1,8 +1,8 @@
"use client";
import Button from "@/app/components/ui/Button";
import Card from "@/app/components/ui/Card";
import PageHeading from "@/app/components/ui/PageHeading";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import Card from "@/lib/components/ui/Card";
import PageHeading from "@/lib/components/ui/PageHeading";
import { useToast } from "@/lib/hooks/useToast";
import Link from "next/link";
import { useRouter } from "next/navigation";

View File

@ -1,9 +1,9 @@
"use client";
import Button from "@/app/components/ui/Button";
import Card from "@/app/components/ui/Card";
import Field from "@/app/components/ui/Field";
import PageHeading from "@/app/components/ui/PageHeading";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import Card from "@/lib/components/ui/Card";
import Field from "@/lib/components/ui/Field";
import PageHeading from "@/lib/components/ui/PageHeading";
import { useToast } from "@/lib/hooks/useToast";
import Link from "next/link";
import { useState } from "react";

View File

@ -1,3 +1,4 @@
import Card from "@/lib/components/ui/Card";
import { FC, ReactNode } from "react";
import {
GiArtificialIntelligence,
@ -7,7 +8,6 @@ import {
GiLockedDoor,
GiOpenBook,
} from "react-icons/gi";
import Card from "../components/ui/Card";
const Features: FC = () => {
return (

View File

@ -1,9 +1,9 @@
"use client";
import Button from "@/lib/components/ui/Button";
import { motion, useScroll, useSpring, useTransform } from "framer-motion";
import Link from "next/link";
import { FC, useRef } from "react";
import { MdNorthEast } from "react-icons/md";
import Button from "../components/ui/Button";
const Hero: FC = () => {
const targetRef = useRef<HTMLDivElement | null>(null);

View File

@ -1,8 +1,8 @@
"use client";
import PageHeading from "@/lib/components/ui/PageHeading";
import useChatsContext from "@/lib/context/ChatsProvider/hooks/useChatsContext";
import { UUID } from "crypto";
import { useEffect } from "react";
import PageHeading from "../../components/ui/PageHeading";
import useChatsContext from "../ChatsProvider/hooks/useChatsContext";
import { ChatInput, ChatMessages } from "../components";
interface ChatPageProps {

View File

@ -1,7 +1,7 @@
"use client";
import Button from "@/lib/components/ui/Button";
import Link from "next/link";
import { MdSettings } from "react-icons/md";
import Button from "../../../../components/ui/Button";
export function ConfigButton() {
return (

View File

@ -1,7 +1,7 @@
"use client";
import Button from "@/lib/components/ui/Button";
import { useSpeech } from "@/lib/context/ChatsProvider/hooks/useSpeech";
import { MdMic, MdMicOff } from "react-icons/md";
import Button from "../../../../components/ui/Button";
import { useSpeech } from "../../../ChatsProvider/hooks/useSpeech";
export function MicButton() {
const { isListening, speechSupported, startListening } = useSpeech();

View File

@ -1,6 +1,6 @@
"use client";
import useChatsContext from "@/app/chat/ChatsProvider/hooks/useChatsContext";
import Button from "../../../../components/ui/Button";
import Button from "@/lib/components/ui/Button";
import useChatsContext from "@/lib/context/ChatsProvider/hooks/useChatsContext";
import { ConfigButton } from "./ConfigButton";
import { MicButton } from "./MicButton";

View File

@ -1,7 +1,7 @@
"use client";
import Card from "@/app/components/ui/Card";
import Card from "@/lib/components/ui/Card";
import useChatsContext from "@/lib/context/ChatsProvider/hooks/useChatsContext";
import { FC, useEffect, useRef } from "react";
import useChatsContext from "../../ChatsProvider/hooks/useChatsContext";
import ChatMessage from "./ChatMessage";
export const ChatMessages: FC = () => {

View File

@ -5,7 +5,7 @@ import { usePathname } from "next/navigation";
import { FC } from "react";
import { FiTrash2 } from "react-icons/fi";
import { MdChatBubbleOutline } from "react-icons/md";
import { Chat } from "../../types";
import { Chat } from "../../../../lib/types/Chat";
interface ChatsListItemProps {
chat: Chat;

View File

@ -1,5 +1,5 @@
"use client";
import useChatsContext from "../../ChatsProvider/hooks/useChatsContext";
import useChatsContext from "@/lib/context/ChatsProvider/hooks/useChatsContext";
import ChatsListItem from "./ChatsListItem";
import { NewChatButton } from "./NewChatButton";
export function ChatsList() {

View File

@ -1,8 +1,8 @@
"use client";
import { ChatsProvider } from "@/lib/context/ChatsProvider/chats-provider";
import { redirect } from "next/navigation";
import { FC, ReactNode } from "react";
import { useSupabase } from "../supabase-provider";
import { ChatsProvider } from "./ChatsProvider/chats-provider";
import { ChatsList } from "./components";
interface LayoutProps {

View File

@ -1,8 +1,8 @@
"use client";
import Field from "@/lib/components/ui/Field";
import { BrainConfig } from "@/lib/context/BrainConfigProvider/types";
import { UseFormRegister } from "react-hook-form";
import Field from "../../components/ui/Field";
interface BackendConfigProps {
register: UseFormRegister<BrainConfig>;

View File

@ -1,7 +1,7 @@
"use client";
import Button from "@/lib/components/ui/Button";
import { useRouter } from "next/navigation";
import Button from "../../components/ui/Button";
import { useConfig } from "../hooks/useConfig";
import { BackendConfig } from "./BackendConfig";
import { ModelConfig } from "./ModelConfig";

View File

@ -1,5 +1,6 @@
"use client";
import Field from "@/lib/components/ui/Field";
import {
BrainConfig,
Model,
@ -8,7 +9,6 @@ import {
paidModels,
} from "@/lib/context/BrainConfigProvider/types";
import { UseFormRegister } from "react-hook-form";
import Field from "../../components/ui/Field";
interface ModelConfigProps {
register: UseFormRegister<BrainConfig>;

View File

@ -1,8 +1,8 @@
"use client";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import Link from "next/link";
import Button from "../../components/ui/Button";
export const UserAccountSection = (): JSX.Element => {
const { session } = useSupabase();

View File

@ -1,6 +1,9 @@
"use client";
import Ellipsis from "@/app/components/ui/Ellipsis";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import { AnimatedCard } from "@/lib/components/ui/Card";
import Ellipsis from "@/lib/components/ui/Ellipsis";
import Modal from "@/lib/components/ui/Modal";
import { useToast } from "@/lib/hooks/useToast";
import { useAxios } from "@/lib/useAxios";
import {
@ -10,10 +13,7 @@ import {
forwardRef,
useState,
} from "react";
import Button from "../../components/ui/Button";
import { AnimatedCard } from "../../components/ui/Card";
import Modal from "../../components/ui/Modal";
import { Document } from "../types";
import { Document } from "../../../lib/types/Document";
import DocumentData from "./DocumentData";
interface DocumentProps {

View File

@ -1,14 +1,15 @@
"use client";
import Button from "@/lib/components/ui/Button";
import Spinner from "@/lib/components/ui/Spinner";
import { Document } from "@/lib/types/Document";
import { useAxios } from "@/lib/useAxios";
import { AnimatePresence, motion } from "framer-motion";
import Link from "next/link";
import { redirect } from "next/navigation";
import { useEffect, useState } from "react";
import Button from "../components/ui/Button";
import Spinner from "../components/ui/Spinner";
import { useSupabase } from "../supabase-provider";
import DocumentItem from "./DocumentItem";
import { Document } from "./types";
export default function ExplorePage() {
const [documents, setDocuments] = useState<Document[]>([]);

View File

@ -1,11 +1,11 @@
import Footer from "@/lib/components/Footer";
import { NavBar } from "@/lib/components/NavBar";
import { ToastProvider } from "@/lib/components/ui/Toast";
import { createServerComponentSupabaseClient } from "@supabase/auth-helpers-nextjs";
import { Analytics } from "@vercel/analytics/react";
import { Inter } from "next/font/google";
import { cookies, headers } from "next/headers";
import { BrainConfigProvider } from "../lib/context/BrainConfigProvider/brain-config-provider";
import Footer from "./components/Footer";
import { NavBar } from "./components/NavBar";
import { ToastProvider } from "./components/ui/Toast";
import "./globals.css";
import SupabaseProvider from "./supabase-provider";

View File

@ -1,7 +1,7 @@
"use client";
import Button from "@/app/components/ui/Button";
import Card from "@/app/components/ui/Card";
import Field from "@/app/components/ui/Field";
import Button from "@/lib/components/ui/Button";
import Card from "@/lib/components/ui/Card";
import Field from "@/lib/components/ui/Field";
import { useCrawler } from "./hooks/useCrawler";
export const Crawler = (): JSX.Element => {

View File

@ -1,7 +1,7 @@
"use client";
import Button from "@/lib/components/ui/Button";
import Card from "@/lib/components/ui/Card";
import { AnimatePresence } from "framer-motion";
import Button from "../../../components/ui/Button";
import Card from "../../../components/ui/Card";
import FileComponent from "./components/FileComponent";
import { useFileUploader } from "./hooks/useFileUploader";

View File

@ -1,8 +1,8 @@
"use client";
import Button from "@/lib/components/ui/Button";
import { Divider } from "@/lib/components/ui/Divider";
import PageHeading from "@/lib/components/ui/PageHeading";
import Link from "next/link";
import Button from "../components/ui/Button";
import { Divider } from "../components/ui/Divider";
import PageHeading from "../components/ui/PageHeading";
import { Crawler } from "./components/Crawler";
import { FileUploader } from "./components/FileUploader";

View File

@ -1,5 +1,5 @@
import { GiBrain } from "react-icons/gi";
import { UserStats } from "../types";
import { UserStats } from "../../../lib/types/User";
export const BrainConsumption = (userStats: UserStats): JSX.Element => {
const { current_brain_size, max_brain_size } = userStats;

View File

@ -1,5 +1,5 @@
import { HTMLAttributes } from "react";
import { UserStats } from "../types";
import { UserStats } from "../../../lib/types/User";
interface DateComponentProps extends HTMLAttributes<HTMLSpanElement> {
date: UserStats["date"];

View File

@ -1,10 +1,10 @@
"use client";
import Button from "@/app/components/ui/Button";
import Button from "@/lib/components/ui/Button";
import { cn } from "@/lib/utils";
import Link from "next/link";
import prettyBytes from "pretty-bytes";
import { HTMLAttributes } from "react";
import { UserStats } from "../types";
import { UserStats } from "../../../lib/types/User";
import { BrainConsumption } from "./BrainConsumption";
import { DateComponent } from "./Date";
import BrainSpaceChart from "./Graphs/BrainSpaceChart";

View File

@ -1,11 +1,11 @@
"use client";
import Spinner from "@/lib/components/ui/Spinner";
import { useAxios } from "@/lib/useAxios";
import { redirect } from "next/navigation";
import { useEffect, useState } from "react";
import Spinner from "../components/ui/Spinner";
import { UserStats } from "../../lib/types/User";
import { useSupabase } from "../supabase-provider";
import { UserStatistics } from "./components/UserStatistics";
import { UserStats } from "./types";
export default function UserPage() {
const [userStats, setUserStats] = useState<UserStats>();

View File

@ -1,4 +1,4 @@
import Button from "@/app/components/ui/Button";
import Button from "@/lib/components/ui/Button";
import Link from "next/link";
import { usePathname } from "next/navigation";

View File

@ -1,7 +1,7 @@
"use client";
import Button from "@/lib/components/ui/Button";
import { FC, useEffect, useLayoutEffect, useState } from "react";
import { MdDarkMode, MdLightMode } from "react-icons/md";
import Button from "../../../../ui/Button";
export const DarkModeToggle: FC = () => {
const [dark, setDark] = useState(false);

View File

@ -1,10 +1,10 @@
"use client";
import { useSupabase } from "@/app/supabase-provider";
import Button from "@/lib/components/ui/Button";
import { cn } from "@/lib/utils";
import Link from "next/link";
import { Dispatch, FC, HTMLAttributes, SetStateAction } from "react";
import { MdPerson, MdSettings } from "react-icons/md";
import Button from "../../../ui/Button";
import { AuthButtons } from "./components/AuthButtons";
import { DarkModeToggle } from "./components/DarkModeToggle";
import { NavLink } from "./components/NavLink";

View File

@ -4,7 +4,7 @@ import { FC } from "react";
import { Header } from "./components/Header";
import { Logo } from "./components/Logo";
import { MobileMenu } from "./components/MobileMenu";
import { NavItems } from "./components/NavItems/";
import { NavItems } from "./components/NavItems";
export const NavBar: FC = () => {
return (

View File

@ -29,9 +29,9 @@ export const anthropicModels = [
// "claude-instant-v1.1-100k",
] as const;
// export const googleModels = ["vertexai"] as const; ## TODO activate when not in demo mode
export const googleModels = ["vertexai"] as const; // TODO activate when not in demo mode
export const googleModels = [] as const;
// export const googleModels = [] as const;
export const models = [
...openAiModels,
...anthropicModels,
@ -40,6 +40,7 @@ export const models = [
export const paidModels= [
...openAiPaidModels,
...googleModels,
] as const;
export type PaidModels = (typeof paidModels)[number];

View File

@ -4,7 +4,7 @@ import { useAxios } from "@/lib/useAxios";
import { UUID } from "crypto";
import { useRouter } from "next/navigation";
import { useCallback, useEffect, useState } from "react";
import { Chat, ChatMessage } from "../../types";
import { Chat, ChatMessage } from "../../../types/Chat";
export default function useChats() {
const [allChats, setAllChats] = useState<Chat[]>([]);

View File

@ -1,5 +1,5 @@
import { isSpeechRecognitionSupported } from "@/lib/helpers/isSpeechRecognitionSupported";
import { useEffect, useState } from "react";
import { isSpeechRecognitionSupported } from "../../helpers/isSpeechRecognitionSupported";
import useChatsContext from "./useChatsContext";
export const useSpeech = () => {

View File

@ -1,5 +1,5 @@
import { ToastContext } from "@/lib/components/ui/Toast/domain/ToastContext";
import { useContext } from "react";
import { ToastContext } from "../../app/components/ui/Toast/domain/ToastContext";
export const useToast = () => {
const { publish } = useContext(ToastContext);

View File

View File

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -5,6 +5,7 @@ module.exports = {
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
'./lib/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {