|
22 | 22 | }, |
23 | 23 | { |
24 | 24 | "cell_type": "code", |
25 | | - "execution_count": 23, |
| 25 | + "execution_count": 1, |
26 | 26 | "id": "be24454d", |
27 | 27 | "metadata": {}, |
28 | 28 | "outputs": [], |
29 | 29 | "source": [ |
30 | | - "from convokit.genai.genai_config import GenAIConfigManager" |
| 30 | + "from convokit.genai.genai_config import GenAIConfigManager\n", |
| 31 | + "config = GenAIConfigManager()\n", |
| 32 | + "from convokit.genai import get_llm_client" |
31 | 33 | ] |
32 | 34 | }, |
33 | 35 | { |
34 | 36 | "cell_type": "code", |
35 | | - "execution_count": null, |
| 37 | + "execution_count": 2, |
36 | 38 | "id": "5666dc72", |
37 | 39 | "metadata": {}, |
38 | 40 | "outputs": [ |
|
45 | 47 | } |
46 | 48 | ], |
47 | 49 | "source": [ |
48 | | - "config = GenAIConfigManager()\n", |
49 | 50 | "config.set_api_key(\"gpt\", \"YOUR API KEY\")\n", |
50 | 51 | "print(f\"Successfully set OpenAI API key in config.\")" |
51 | 52 | ] |
|
62 | 63 | }, |
63 | 64 | { |
64 | 65 | "cell_type": "code", |
65 | | - "execution_count": 25, |
| 66 | + "execution_count": null, |
66 | 67 | "id": "220c33fe", |
67 | 68 | "metadata": {}, |
68 | 69 | "outputs": [], |
69 | 70 | "source": [ |
70 | | - "from convokit.genai import get_llm_client\n", |
71 | | - "\n", |
72 | 71 | "MODEL_PROVIDER = \"gpt\"\n", |
73 | 72 | "client = get_llm_client(MODEL_PROVIDER, config)" |
74 | 73 | ] |
|
96 | 95 | "print(\"Latency:\", response.latency)" |
97 | 96 | ] |
98 | 97 | }, |
| 98 | + { |
| 99 | + "cell_type": "markdown", |
| 100 | + "id": "417c22b9", |
| 101 | + "metadata": {}, |
| 102 | + "source": [ |
| 103 | + "# Setup ConvoKit GenAI with Google Gemini Through Gemini Developer API" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "markdown", |
| 108 | + "id": "94aede45", |
| 109 | + "metadata": {}, |
| 110 | + "source": [ |
| 111 | + "Checkout Google Gemini Developer API: https://ai.google.dev/gemini-api/docs/" |
| 112 | + ] |
| 113 | + }, |
| 114 | + { |
| 115 | + "cell_type": "code", |
| 116 | + "execution_count": null, |
| 117 | + "id": "0a4c8e31", |
| 118 | + "metadata": {}, |
| 119 | + "outputs": [], |
| 120 | + "source": [ |
| 121 | + "MODEL_PROVIDER = \"gemini\"\n", |
| 122 | + "MODEL = \"gemini-2.5-flash\"\n", |
| 123 | + "config.set_api_key(\"gemini\", \"YOUR API KEY\")" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": 8, |
| 129 | + "id": "88eef33f", |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [ |
| 132 | + { |
| 133 | + "name": "stdout", |
| 134 | + "output_type": "stream", |
| 135 | + "text": [ |
| 136 | + "Text: ConvoKit is a powerful Python library designed for the **systematic analysis of conversational data**. It provides a unified framework to represent, transform, and analyze conversations, moving beyond simple text analysis to focus on the rich structure and dynamics inherent in human (and human-like) interactions.\n", |
| 137 | + "\n", |
| 138 | + "Here's a breakdown of what you can do with ConvoKit:\n", |
| 139 | + "\n", |
| 140 | + "1. **Represent Conversational Data:**\n", |
| 141 | + " * **Standardized Structure:** ConvoKit allows you to load diverse conversational datasets (chat logs, forum posts, emails, transcripts, etc.) into a standardized `Corpus` object, which consists of `Utterance` and `Speaker` objects. This makes it easy to work with different datasets consistently.\n", |
| 142 | + " * **Metadata Storage:** You can attach arbitrary metadata to conversations, utterances, and speakers (e.g., speaker demographics, conversation topics, timestamps, sentiment scores).\n", |
| 143 | + "\n", |
| 144 | + "2. **Preprocess and Enrich Conversational Data:**\n", |
| 145 | + " * **Tokenization & Linguistic Features:** Integrate with spaCy to perform tokenization, part-of-speech tagging, named entity recognition, and dependency parsing on utterances.\n", |
| 146 | + " * **Sentiment Analysis:** Apply pre-trained sentiment models to utterances to understand emotional tone.\n", |
| 147 | + " * **Dialog Act Classification:** Use models to classify the communicative function of an utterance (e.g., question, statement, agreement, disagreement).\n", |
| 148 | + " * **Speaker Attributes:** Extract features related to speakers, such as their average utterance length, lexical diversity, or frequency of certain dialog acts.\n", |
| 149 | + "\n", |
| 150 | + "3. **Analyze Conversational Dynamics and Structure:**\n", |
| 151 | + " * **Turn-Taking Patterns:** Investigate how speakers take turns, who initiates conversations, and who responds.\n", |
| 152 | + " * **Interaction Networks:** Build and analyze networks of who talks to whom, identifying central speakers or conversational hubs.\n", |
| 153 | + " * **Topic Modeling:** Discover latent topics within conversations and track how topics shift over time or across different speakers.\n", |
| 154 | + " * **Power and Dominance:** Analyze linguistic cues and interaction patterns that might indicate power dynamics or dominance within a conversation (e.g., interruption patterns, question-asking behavior).\n", |
| 155 | + " * **Coherence and Cohesion:** Study how utterances relate to each other to form coherent conversations.\n", |
| 156 | + "\n", |
| 157 | + "4. **Extract Features for Machine Learning:**\n", |
| 158 | + " * **Linguistic Features:** Extract features like word counts, TF-IDF, n-grams, lexical diversity, specific part-of-speech frequencies.\n", |
| 159 | + " * **Social Features:** Features related to speaker roles, interaction frequency, or network centrality.\n", |
| 160 | + " * **Structural Features:** Features related to turn-taking, utterance position in a conversation, or response time.\n", |
| 161 | + " * These features can then be used to train models for tasks like speaker classification, conversation summarization, or predicting conversation outcomes.\n", |
| 162 | + "\n", |
| 163 | + "5. **Conduct Comparative Studies:**\n", |
| 164 | + " * **Compare Groups:** Analyze differences in communication styles, sentiment, or interaction patterns between different groups of speakers (e.g., male vs. female, expert vs. novice, different customer segments).\n", |
| 165 | + " * **Compare Contexts:** Study how conversations differ across various contexts (e.g., formal vs. informal, online vs. offline, different platforms).\n", |
| 166 | + "\n", |
| 167 | + "6. **Specific Use Cases:**\n", |
| 168 | + "\n", |
| 169 | + " * **Social Science Research:** Studying group dynamics, power structures, communication styles, and social phenomena in online communities, political debates, or interviews.\n", |
| 170 | + " * **Customer Service Analytics:** Identifying common customer issues, evaluating agent performance, detecting customer frustration, and optimizing chatbot interactions.\n", |
| 171 | + " * **Product Analytics:** Understanding how users interact with a product through chat, forums, or reviews; identifying pain points or feature requests.\n", |
| 172 | + " * **Content Moderation:** Detecting toxic language, harassment, or hate speech by analyzing conversational context and patterns, not just isolated words.\n", |
| 173 | + " * **Chatbot Development:** Analyzing user input to improve chatbot understanding, evaluating dialog flow, and benchmarking chatbot responses against human conversations.\n", |
| 174 | + " * **Digital Humanities:** Analyzing historical texts, interviews, or literary dialogues to uncover linguistic and social insights.\n", |
| 175 | + " * **Linguistic Research:** Investigating specific linguistic phenomena, such as politeness strategies, code-switching, or the use of discourse markers in natural conversation.\n", |
| 176 | + "\n", |
| 177 | + "In essence, ConvoKit empowers researchers and data scientists to move beyond simple text analysis and delve into the rich, structured world of conversations, enabling deeper insights into human communication.\n" |
| 178 | + ] |
| 179 | + } |
| 180 | + ], |
| 181 | + "source": [ |
| 182 | + "client = get_llm_client(model=MODEL, provider=MODEL_PROVIDER, config_manager=config)\n", |
| 183 | + "response = client.generate(\"What can you do with ConvoKit.\")\n", |
| 184 | + "print(\"Text:\", response.text)" |
| 185 | + ] |
| 186 | + }, |
99 | 187 | { |
100 | 188 | "cell_type": "markdown", |
101 | 189 | "id": "33b72969", |
|
114 | 202 | "outputs": [], |
115 | 203 | "source": [ |
116 | 204 | "MODEL_PROVIDER = \"gemini\"\n", |
117 | | - "MODEL = \"gemini-2.0-flash-001\"\n", |
| 205 | + "MODEL = \"gemini-2.5-flash\"\n", |
118 | 206 | "config.set_google_cloud_config(\"YOUR PROJECT\", \"YOUR LOCATION\")" |
119 | 207 | ] |
120 | 208 | }, |
121 | 209 | { |
122 | 210 | "cell_type": "code", |
123 | | - "execution_count": 28, |
| 211 | + "execution_count": null, |
124 | 212 | "id": "32fad57a", |
125 | 213 | "metadata": {}, |
126 | 214 | "outputs": [ |
|
136 | 224 | } |
137 | 225 | ], |
138 | 226 | "source": [ |
139 | | - "client = get_llm_client(MODEL_PROVIDER, config)\n", |
| 227 | + "client = get_llm_client(model=MODEL, provider=MODEL_PROVIDER, config_manager=config, use_vertex_ai=True)\n", |
140 | 228 | "response = client.generate(\"Tell me a fun fact about Cornell University.\")\n", |
141 | 229 | "print(\"Text:\", response.text)" |
142 | 230 | ] |
|
310 | 398 | ], |
311 | 399 | "metadata": { |
312 | 400 | "kernelspec": { |
313 | | - "display_name": "Python 3", |
| 401 | + "display_name": "convokit", |
314 | 402 | "language": "python", |
315 | 403 | "name": "python3" |
316 | 404 | }, |
|
324 | 412 | "name": "python", |
325 | 413 | "nbconvert_exporter": "python", |
326 | 414 | "pygments_lexer": "ipython3", |
327 | | - "version": "3.11.5" |
| 415 | + "version": "3.12.11" |
328 | 416 | } |
329 | 417 | }, |
330 | 418 | "nbformat": 4, |
|
0 commit comments