青麈 commited on
Commit
684ee31
·
1 Parent(s): 96d3768
Files changed (5) hide show
  1. .gitignore +11 -0
  2. LICENSE +21 -0
  3. README.md +24 -12
  4. main.py +55 -0
  5. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+
7
+ # Directories
8
+ __pycache__
9
+
10
+ # Files
11
+ .DS_Store
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Leric Dax (LAK), Mnemosyne Labs, and Azoth Corp.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,12 +1,24 @@
1
- ---
2
- title: Claude100K API
3
- emoji: 💻
4
- colorFrom: indigo
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 3.35.2
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AnthropologAI
2
+ quick gradio chat interface for Anthropic AI's API for Claude, including 100k
3
+
4
+
5
+ # Anthropic AI Chatbot
6
+
7
+ This is a simple chatbot that uses the Anthropic AI API to generate responses. It uses the Gradio library to provide a basic chat interface.
8
+
9
+ ## Installation
10
+
11
+ First, clone this repository to your local machine using `git clone https://github.com/AzothCorp/AnthropologAI.git`.
12
+
13
+ Then, navigate to the project directory and install the necessary dependencies using `pip install -r requirements.txt`.
14
+
15
+ ## Usage
16
+
17
+ Run the script using `python main.py`.
18
+
19
+ This will launch a Gradio interface in your web browser where you can interact with the chatbot.
20
+
21
+ ## License
22
+
23
+ This project is licensed under the terms of the MIT license.
24
+ By Leric Dax (LAK), Mnemosyne Labs, and Azoth Corp (2023).
main.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+
5
+ # Define a global variable for the conversation history
6
+ conversation_history = ""
7
+
8
+ def chat_with_ai(user_question, api_key, model):
9
+ global conversation_history
10
+
11
+ # Instantiate the endpoint URL
12
+ url = 'https://api.anthropic.com/v1/complete'
13
+
14
+ # Define the headers for the HTTP request
15
+ headers = {
16
+ 'Content-Type': 'application/json',
17
+ 'X-API-Key': api_key,
18
+ }
19
+
20
+ # Define the parameters for the request
21
+ params = {
22
+ 'prompt': f'{conversation_history}\n\nHuman: {user_question}\n\nAssistant:',
23
+ 'model': model,
24
+ 'max_tokens_to_sample': 4000,
25
+ 'stop_sequences': ['\n\nHuman:'],
26
+ 'temperature': 0.8,
27
+ 'top_p': -1,
28
+ 'metadata': {}
29
+ }
30
+
31
+ # Convert the params dict to a JSON string
32
+ params_json = json.dumps(params)
33
+
34
+ # Send the HTTP request to the API
35
+ response = requests.post(url, headers=headers, data=params_json)
36
+
37
+ # Check if the request was successful
38
+ if response.status_code == 200:
39
+ # Parse the JSON response
40
+ response_json = response.json()
41
+ conversation_history += f'\n\nHuman: {user_question}\n\nAssistant: {response_json["completion"]}'
42
+
43
+ # Return the entire conversation history
44
+ return conversation_history
45
+ else:
46
+ return f'Error: {response.status_code}'
47
+
48
+ # Define the model options
49
+ model_options = ["claude-v1", "claude-v1-100k", "claude-v1.0", "claude-v1.2", "claude-v1.3", "claude-v1.3-100k", "claude-instant-v1", "claude-instant-v1-100k", "claude-instant-v1.0", "claude-instant-v1.1", "claude-instant-v1.1-100k"]
50
+
51
+ iface = gr.Interface(fn=chat_with_ai,
52
+ inputs=["text", "text", gr.inputs.Dropdown(model_options)],
53
+ outputs="text",
54
+ layout="vertical")
55
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ requests