Home 研究生工具—CoGPT (开发者删库了,建议别用了)
Post
Cancel

研究生工具—CoGPT (开发者删库了,建议别用了)

介绍

前置配置

  • GitHub Pro (可以通过学生邮箱去申请)
  • Copilot (Github Pro可以免费申请)
  • 操作系统:Windows

部署及使用

CoGPT搭建

Windows配置

ChatGPT-Next-Web 中给出了配置教程,这里重述并补充一点细节

  • 下载

Releases 页面下载Windows对应的版本,解压,在该文件夹中,创建一个 cogpt-api-service.ps1 文件,将 cogpt-api-service 中的内容复制到 cogpt-api-service.ps1,也可直接复制下面的内容:

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
$taskName = "cogpt-api"
$programPath = Join-Path $PSScriptRoot "cogpt-api.exe"
$workingDir = $PSScriptRoot

# check if Administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $isAdmin) {
    Write-Host "Please run this script as Administrator."
    exit
}

if ($args[0] -eq "enable") {
    # first check if the task exists
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -ne $null) {
        Write-Host "Task $taskName already exists."
        $status = Get-ScheduledTask -TaskName $taskName | Select-Object State
        if ($status.State -eq "Running") {
            Write-Host "Task $taskName is already running."
        } else {
            Start-ScheduledTask -TaskName $taskName
            Write-Host "Task $taskName started."
        }
    } else {
        Write-Host "Creating task $taskName..."
        $action = New-ScheduledTaskAction -Execute $programPath -WorkingDirectory $workingDir
        $trigger = New-ScheduledTaskTrigger -AtStartup
        $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -DontStopOnIdleEnd
        $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount
        Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Principal $principal
        Start-ScheduledTask -TaskName $taskName
        Write-Host "Task $taskName created."
    }
} elseif ($args[0] -eq "disable") {
    # first check if the task exists
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -eq $null) {
        Write-Host "Task $taskName does not exist."
    } else {
        Write-Host "Deleting task $taskName..."
        Stop-ScheduledTask -TaskName $taskName
        Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
        Write-Host "Task $taskName deleted."
    }
} elseif ($args[0] -eq "start") {
    # first check if the task exists
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -eq $null) {
        Write-Host "Task $taskName does not exist. Please enable it first."
    } else {
        Write-Host "Starting task $taskName..."
        Start-ScheduledTask -TaskName $taskName
        Write-Host "Task $taskName started."
    }
} elseif ($args[0] -eq "stop") {
    # first check if the task exists
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -eq $null) {
        Write-Host "Task $taskName does not exist. Please enable it first."
    } else {
        Write-Host "Stopping task $taskName..."
        Stop-ScheduledTask -TaskName $taskName
        Write-Host "Task $taskName stopped."
    }
} elseif ($args[0] -eq "restart") {
    # first check if the task exists
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -eq $null) {
        Write-Host "Task $taskName does not exist. Please enable it first."
    } else {
        Write-Host "Restarting task $taskName..."
        Restart-ScheduledTask -TaskName $taskName
        Write-Host "Task $taskName restarted."
    }
} elseif ($args[0] -eq "status") {
    # first check if the task exists
    $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -eq $null) {
        Write-Host "Task $taskName does not exist. Please enable it first."
    } else {
        $status = Get-ScheduledTask -TaskName $taskName | Select-Object State
        if ($status.State -eq "Running") {
            Write-Host "Task $taskName is running."
        } else {
            Write-Host "Task $taskName is not running."
        }
    }
} else {
    Write-Host "Please specify 'enable' or 'disable'."
}
  • 配置

在解压的文件里,创建 .env 文件,编辑该文件添加键值对以设置服务的配置,支持的配置见 .env配置,以改端口为例(默认端口为8080,这里将端口改为12345):

1
PORT=12345
  • 启动

在该文件夹内,以 管理员权限 打开 PowerShell 并运行下面的命令:

1
.\cogpt-api-service.ps1 enable

下面是所有可以使用的命令。所有命令都应该在 PowerShell 以管理员权限运行。

1
2
3
4
5
6
./cogpt-api-service.ps1 enable  # 启用并启动服务
./copgt-api-service.ps1 disable # 停止并禁用服务
./cogpt-api-service.ps1 start   # 启动服务
./cogpt-api-service.ps1 stop    # 停止服务
./cogpt-api-service.ps1 restart # 重启服务
./cogpt-api-service.ps1 status  # 检查服务状态
  • 验证

浏览器访问 http://localhost:port (port没改的话默认为8080),能得到 Hi, it's CoGPT! 的提示即为启动成功

  • Token生成

运行 cogpt-get-apptoken.exe,按照提示进行,在GitHub上完成授权,得到Token

ChatGPT-Next-Web

自建

有服务器的可以自行搭建,搭建过程较为简单,省略

白嫖

使用官方搭建好的网站:NextChat,左下角设置,勾选自定义EndPoint,URL输入http://<ip>:<port>,如http://localhost:12345,API Key填入前面生成的Token,模型选择GPT4:

测试

可以问:鲁迅为什么暴打周树人?能得到鲁迅和周树人是同一个人则为GPT4

TODO

This post is licensed under CC BY 4.0 by the author.