File size: 2,491 Bytes
411594c
52a666d
 
f18fc21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52a666d
 
 
 
 
9edfe29
f24f826
 
 
9edfe29
 
 
411594c
ed59e1c
004f7cf
 
172448d
004f7cf
 
 
 
 
 
172448d
004f7cf
 
13a2e4f
004f7cf
 
 
 
 
 
 
 
 
 
 
 
f18fc21
 
 
905f9b8
004f7cf
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import streamlit as st
import requests
import datetime
import openai
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

import os
from dotenv import load_dotenv
load_dotenv()

# Prompt Template
prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are a helpful. Please respond to the user's questions."),
        ("user", "Question: {question}")
    ]
)

def generate_response(question, openai_api_key, model, temperature, max_tokens):
    model = ChatOpenAI(model_name=model, temperature=temperature, max_tokens=max_tokens, openai_api_key=openai_api_key)
    output_parser = StrOutputParser()
    chain = prompt | model | output_parser
    answer = chain.invoke({'question': question})
    return answer

st.title("Q&A Chatbot with OpenAI")

# Sidebar
st.sidebar.title("Settings")
openai_api_key = st.sidebar.text_input("Enter your OpenAI API Key", type="password")

# Dropdown for OpenAI models
model = st.sidebar.selectbox("Select OpenAI Model", ["gpt-4o", "gpt-4-turbo", "gpt-4"])

# Slider for temperature
temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.5)

# Slider for max tokens
max_tokens = st.sidebar.slider("Max Tokens", 50, 500, 100)

# Text Input for user question
question = st.text_input("Enter your question")

if st.button("Get Answer"):
    if openai_api_key:
        answer = generate_response(question, openai_api_key, model, temperature, max_tokens)
        st.write(answer)
    else:
        st.write("Please enter your OpenAI API Key")









# 現在の使用量を取得

usage = 0
#openai.billing.usage()
print(usage)
st.write(usage)

x = st.slider('Select a value')
st.write(x, 'Three is', x * x * x)

# Title of the app
st.title('単純な計算機')

# Create input fields for numbers
num1 = st.number_input('Enter first number:', value=0.0)
num2 = st.number_input('Enter second number:', value=0.0)

# Create selectbox for operations
operation = st.selectbox('Choose operation:', ('足し算', 'Subtract', 'Multiply', 'Divide'))

# Define the operations
if operation == '足し算':
    result = num1 + num2
elif operation == 'Subtract':
    result = num1 - num2
elif operation == 'Multiply':
    result = num1 * num2
elif operation == 'Divide':
    if num2 != 0:
        result = num1 / num2
    else:
        result = 'Error: Division by zero'

# Display the result
st.write(f'The result of {operation} is: {result}')