File size: 3,483 Bytes
45b200f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300566c
45b200f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from typing import TypedDict, Annotated, Literal, Union, Any, List, Tuple
"""
Typing:
Union = either type A or type B
Optional = either type A or None
Literal = only specific values (constants), not any value of a type
"""
from pydantic import BaseModel
import os
import re
import random
import requests
import inspect
import subprocess

import gradio as gr
import pandas as pd
# from lmnr import Laminar
from dotenv import load_dotenv
load_dotenv()
from together import Together
import base64
import yt_dlp

import datasets
from datasets import load_dataset
from huggingface_hub import list_models
from langchain.docstore.document import Document
from langchain_community.retrievers import BM25Retriever
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_community.document_loaders import UnstructuredExcelLoader
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain.tools import Tool
from langchain_ollama import ChatOllama
from langchain_together import ChatTogether
from langchain_huggingface import HuggingFaceEndpoint,ChatHuggingFace
from langchain_core.messages import AnyMessage, HumanMessage, AIMessage, SystemMessage, ToolMessage
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import tools_condition, ToolNode
from langsmith import traceable



# GLOBALS
HF_TOKEN = os.getenv('HF_TOKEN')
LAMINAR_API_KEY = os.getenv('LAMINAR_API_KEY')
# from the task
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
api_url = DEFAULT_API_URL
questions_url = f"{api_url}/questions"
submit_url = f"{api_url}/submit"
file_url = f"{api_url}/files"

# DEFAULT_SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."""
DEFAULT_SYSTEM_PROMPT = """
You are a general AI assistant. 
I will ask you a question. 
Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. 
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. 
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. 
If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
"""
# Think step by step. On every step use a tool if it is needed. Make multiple tool calls if required.
DEFAULT_SYSTEM_PROMPT = DEFAULT_SYSTEM_PROMPT.replace("\n", "")


# model_name = 'qwen3:8b'
model_name = 'llama3.2:latest'