File size: 1,269 Bytes
734db66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain.llms.base import LLM
from typing import Optional, List, Mapping, Any
import anthropic
from urllib.parse import urlparse
import os
class ClaudeLLM(LLM):

    @property
    def _llm_type(self) -> str:

        return "custom"

    def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:


        client = anthropic.Client(os.environ['ANTHROPIC_KEY'])


        # How about the formatted prompt?
        prompt_formatted = (
        f"{anthropic.HUMAN_PROMPT}{prompt}\n{anthropic.AI_PROMPT}"
        )


        response = client.completion(
        prompt=prompt_formatted,
        stop_sequences=[anthropic.HUMAN_PROMPT],
        model="claude-instant-v1-100k",
        max_tokens_to_sample=100000,
        temperature=0.3,
         )

        return response["completion"]

    @property
    def _identifying_params(self) -> Mapping[str, Any]:
        """Get the identifying parameters."""
        return {

        }
        
def remove_numbers(question):
    return question.translate(str.maketrans('', '', '0123456789'))

def extract_website_name(url):
    parsed_url = urlparse(url)
    if parsed_url.netloc.startswith("www."):
        return parsed_url.netloc.split("www.")[1].split(".")[0]
    return parsed_url.netloc.split(".")[0]