File size: 4,927 Bytes
acd4cb0
eeeb58e
acd4cb0
eeeb58e
 
acd4cb0
a2e761d
acd4cb0
 
eeeb58e
acd4cb0
 
eeeb58e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
title: TradeVerse AI Trading Experiment
emoji: πŸ“ˆ
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
---

# TradeVerse AI Trading Experiment

A psychology research tool for studying human-AI interaction in financial decision-making.

## Overview

This application combines:
- **Trading Game**: Scenario-based trading decisions in a fictional financial universe
- **AI Chatbot**: RAG-based advisor with tunable parameters
- **Experiment Tracking**: Comprehensive data collection for research analysis

## Features

### For Participants
- Interactive trading scenarios with fictional companies
- AI advisor that provides recommendations and answers questions
- Adjustable AI settings (explanation depth, communication style)
- Real-time portfolio tracking

### For Researchers
- Pre-defined experimental conditions for A/B testing
- Hidden parameters (accuracy rate, confidence framing, risk bias)
- Comprehensive tracking of:
  - Trading decisions and outcomes
  - AI consultation patterns
  - Trust metrics and confidence changes
  - Response timing
- Data export utilities (CSV, Excel reports)

## Experimental Conditions

| Condition | Accuracy | Confidence | Description |
|-----------|----------|------------|-------------|
| high_accuracy_high_confidence | 85% | High | Correct AI, assertive |
| high_accuracy_low_confidence | 85% | Low | Correct AI, hedging |
| low_accuracy_high_confidence | 40% | High | Often wrong, assertive |
| low_accuracy_low_confidence | 40% | Low | Often wrong, hedging |
| conservative_advisor | 70% | Medium | Risk-averse recommendations |
| aggressive_advisor | 70% | Medium | Risk-seeking recommendations |
| passive_advisor | 70% | Low proactivity | Rarely initiates |
| active_advisor | 70% | High proactivity | Frequently initiates |

## Setup

### LLM Provider Options

The chatbot supports multiple LLM providers (auto-detected based on available API keys):

| Provider | Env Variable | Cost | Notes |
|----------|--------------|------|-------|
| **HuggingFace** | `HF_TOKEN` | Free tier available | Recommended for HF Spaces |
| DeepSeek | `DEEPSEEK_API_KEY` | Pay-per-use | Higher quality |
| Fallback | None needed | Free | Rule-based, limited |

#### Recommended HuggingFace Models (free tier)

```python
# In chatbot.py, change DEFAULT_HF_MODEL to any of these:
"Qwen/Qwen2-1.5B-Instruct"             # Smallest, fastest
"microsoft/Phi-3-mini-4k-instruct"     # Small, good quality
"HuggingFaceH4/zephyr-7b-beta"         # Default, best quality
"mistralai/Mistral-7B-Instruct-v0.2"   # Popular alternative
```

### Environment Variables

**Option 1: HuggingFace (Recommended for HF Spaces)**
```bash
export HF_TOKEN="hf_your_token_here"
```
Get your token at: https://huggingface.co/settings/tokens

**Option 2: DeepSeek**
```bash
export DEEPSEEK_API_KEY="your-api-key-here"
```

### Local Development

```bash
pip install -r requirements.txt
python app.py
```

### Hugging Face Spaces

1. Create a new Space with Gradio SDK
2. Upload all files
3. Add `HF_TOKEN` as a secret in Space settings (Settings β†’ Repository secrets)
   - Your HF token works automatically in Spaces

## Data Export

```bash
# Quick statistics
python export_data.py stats

# Export all data to CSV
python export_data.py export

# Generate full Excel report
python export_data.py report
```

## Project Structure

```
IntegratedGame/
β”œβ”€β”€ app.py                 # Main Gradio application
β”œβ”€β”€ trading.py             # Trading engine and portfolio management
β”œβ”€β”€ chatbot.py             # RAG chatbot with parameter-aware responses
β”œβ”€β”€ tracking.py            # Database and experiment tracking
β”œβ”€β”€ config.py              # Scenarios, conditions, parameters
β”œβ”€β”€ export_data.py         # Data analysis and export
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ knowledge_base/
β”‚   β”œβ”€β”€ companies.txt      # Fictional company profiles
β”‚   β”œβ”€β”€ market_context.txt # TradeVerse economic backdrop
β”‚   β”œβ”€β”€ trading_basics.txt # Trading fundamentals
β”‚   └── ai_persona.txt     # AI behavior guidelines
└── db/
    └── experiment.db      # SQLite database (auto-created)
```

## Database Schema

### sessions
- Participant sessions with portfolio tracking
- AI reliance metrics

### decisions
- Individual trading decisions
- AI parameters at decision time
- Timing and confidence data

### chat_interactions
- All AI-participant conversations
- Proactive vs reactive classification
- Engagement metrics

### trust_metrics
- Pre/post advice confidence
- Advice adherence
- Outcome tracking

## Research Applications

This tool supports research into:
- Trust calibration in AI advisors
- Effect of AI confidence framing on decision-making
- Proactive vs reactive AI assistance preferences
- Risk perception under AI guidance
- Learning and adaptation to AI accuracy

## License

MIT License