Skip to content

Commit a98dfaa

Browse files
B13rgIvanIsCoding
andauthored
Add Self-hosted api option (#31)
* feat: Add self-hosted server option * update faq * typo * Add env vars and expose port to dockerfile * Update src/pages/03_FAQ.py --------- Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
1 parent e33346a commit a98dfaa

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ RUN pip install -r requirements.txt && \
1818
# Copy the current code to the
1919
COPY . .
2020

21+
ENV GEMINI_API_KEY=''
22+
ENV OPENAI_API_KEY=''
23+
EXPOSE 8501
24+
2125
# Run ResuLLMe with Streamlit
2226
CMD [ "streamlit", "run", "src/Main.py" ]

src/Main.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def select_llm_model():
1414
model_type = st.selectbox(
1515
"Select the model you want to use:",
16-
["OpenAI", "Gemini"],
16+
["OpenAI", "Gemini", "Self-Hosted"],
1717
index=0
1818
)
1919
return model_type
@@ -32,14 +32,43 @@ def get_llm_model_and_api(model_type):
3232
["gpt-3.5-turbo", "gpt-4-turbo", "gpt-4o"],
3333
index=0,
3434
)
35-
else:
35+
elif model_type == "Gemini":
3636
api_key = os.getenv("GEMINI_API_KEY")
3737
if not api_key:
3838
api_key = st.text_input(
3939
"Enter your Gemini API Key: [(contact Gemini support for more details)]",
4040
type="password",
4141
)
4242
api_model = "gemini-1.5-flash"
43+
else:
44+
if os.getenv("GEMINI_API_KEY"):
45+
api_key = os.getenv("GEMINI_API_KEY")
46+
elif os.getenv("OPENAI_API_KEY"):
47+
api_key = os.getenv("OPENAI_API_KEY")
48+
if not api_key:
49+
api_key = st.text_input(
50+
"Enter the self-hosted API key: [(Most times you can just write random text)]",
51+
type="password",
52+
)
53+
# Use Ollama API as default
54+
location = "http://127.0.0.1:11434/v1"
55+
location = st.text_input(
56+
"Enter the self-hosted API location (e.g. " + location + "):",
57+
type="default"
58+
)
59+
model_list = []
60+
try:
61+
client = openai.OpenAI(base_url=location, api_key=api_key)
62+
model_list = [model.id for model in client.models.list()]
63+
except:
64+
st.markdown(
65+
"The current API key or location is incorrect. Please try again."
66+
)
67+
api_model = st.selectbox(
68+
"Select a model to use for the LLMs:",
69+
model_list,
70+
index=0
71+
)
4372
return api_key, api_model
4473

4574

src/pages/03_FAQ.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
with st.expander("**Do I need an OpenAI/Gemini API Key to run ResuLLMe?**"):
1313
st.markdown(
1414
"""
15-
**Yes**, as we currently only support ChatGPT and Google Gemini. You can obtain your key [openai](https://platform.openai.com/account/api-keys)/[Gemini](https://aistudio.google.com/ ).
15+
**No**, Resullme is able to use any OpenAPI-compatible endpoint, such as [Ollama](https://github.com/ollama/ollama). If you intend on using ChatGPT or Google Gemini, an API key is required. You can obtain your key [openai](https://platform.openai.com/account/api-keys)/[Gemini](https://aistudio.google.com/ ).
1616
"""
1717
)
1818

1919
with st.expander("**Can I store my OpenAI/Gemini API Key instead of manually re-entering it?**"):
2020
st.markdown(
2121
"""
22-
**Yes**, you can store your key in an environment variable `OPENAI_API_KEY` for openAI or `GEMINI_API_KEY` for Google Gemini, but if the environment variable `OPENAI_API_KEY`/`GEMINI_API_KEY` is not defined, ResuLLMe will prompt the user for a key.
22+
**Yes**, you can store your key in an environment variable. Use `OPENAI_API_KEY` for openAI, `GEMINI_API_KEY` for Google Gemini, and either for self-hosted. If the environment variable `OPENAI_API_KEY`/`GEMINI_API_KEY` is not defined, ResuLLMe will prompt the user for a key.
2323
"""
2424
)
2525

0 commit comments

Comments
 (0)