jeongsk commited on
Commit
74e9aa3
Β·
1 Parent(s): 9e4f83d

feat: Add chatbot functionality using OpenAI API

Browse files
Files changed (1) hide show
  1. laas_agent.ipynb +107 -0
laas_agent.ipynb ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import os\n",
10
+ "from dotenv import load_dotenv\n",
11
+ "from openai import OpenAI\n",
12
+ "from langchain_core.messages import AIMessage\n",
13
+ "_ = load_dotenv()"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "client = OpenAI(\n",
23
+ " api_key=\"LAAS\",\n",
24
+ " base_url=\"https://api-laas.wanted.co.kr/api/preset/\",\n",
25
+ ")"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 3,
31
+ "metadata": {},
32
+ "outputs": [],
33
+ "source": [
34
+ "def chatbot(message: str):\n",
35
+ " response = client.chat.completions.create(\n",
36
+ " extra_headers={\n",
37
+ " \"apiKey\": os.environ.get(\"LAAS_API_KEY\"),\n",
38
+ " \"project\": os.environ.get(\"LAAS_PROJECT\"),\n",
39
+ " },\n",
40
+ " extra_body={\n",
41
+ " \"hash\": \"d33f1c5fe1f4c091a88357b61f8638599b5556445454a87ef0a1a6d35846fe0d\",\n",
42
+ " },\n",
43
+ " model=\"gpt-4o-mini\",\n",
44
+ " messages=[\n",
45
+ " {\n",
46
+ " \"role\": \"system\",\n",
47
+ " \"content\": \"Talk like a close friend and use emojis 😊\",\n",
48
+ " },\n",
49
+ " {\n",
50
+ " \"role\": \"user\",\n",
51
+ " \"content\": message,\n",
52
+ " },\n",
53
+ " ],\n",
54
+ " )\n",
55
+ " return response.choices[0].message.content"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": 4,
61
+ "metadata": {},
62
+ "outputs": [
63
+ {
64
+ "data": {
65
+ "text/plain": [
66
+ "'μ•ˆλ…•ν•˜μ„Έμš”! 😊 μ–΄λ–»κ²Œ 지내고 μžˆμ–΄? μš”μ¦˜ 뭐 ν•˜κ³  지내?'"
67
+ ]
68
+ },
69
+ "execution_count": 4,
70
+ "metadata": {},
71
+ "output_type": "execute_result"
72
+ }
73
+ ],
74
+ "source": [
75
+ "chatbot(\"μ•ˆλ…•ν•˜μ„Έμš”\")"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": null,
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": []
84
+ }
85
+ ],
86
+ "metadata": {
87
+ "kernelspec": {
88
+ "display_name": "careeradvisepro-5HRZYKsZ-py3.11",
89
+ "language": "python",
90
+ "name": "python3"
91
+ },
92
+ "language_info": {
93
+ "codemirror_mode": {
94
+ "name": "ipython",
95
+ "version": 3
96
+ },
97
+ "file_extension": ".py",
98
+ "mimetype": "text/x-python",
99
+ "name": "python",
100
+ "nbconvert_exporter": "python",
101
+ "pygments_lexer": "ipython3",
102
+ "version": "3.11.9"
103
+ }
104
+ },
105
+ "nbformat": 4,
106
+ "nbformat_minor": 2
107
+ }