当前位置: 首页 > news >正文

Xamarin.Android实现本地化部署DeepSeek的对话功能

1、背景

时间飞逝啊!春节期间大火的DeepSeek,假期还没结束,就赶紧自己部署了一个R1的最低版本(1.5B),顺便在App上通过API实现与本地DeepSeek的对话功能。这几天睡眠不好,写了几篇,正好总结及记录一下吧

2、效果

整体的效果如视频所示。【说明】当时整的时候,只是一个最简单的http请求,没有使用SignalR,改天再加上试试

Xamarin.Android实现DeepSeek的对话功能

3、具体实现

3.1 .9.png图(点九图)

首先是对话框,就是下图中的聊天框的蓝色和灰色的区域,在Android开发中经常使用后缀名称为.9.png的图片,作为存放文字的区域。
在这里插入图片描述
先说一下.9.png的逻辑
在这里插入图片描述
上面的横线,代表整个对话框左右移动的区域,左侧是上下移动的区域;而右面的横线则是文字在垂直方向的存放区域,下方的则是文字在水平方向的存放区域。大体如下图所示
在这里插入图片描述
如何画出这个界面,网上的方法有很多,这里介绍一个很简单的。登录这个网址:Android Asset Studio,选择这个,进行尝试即可,非常简单。这个网站还有很多其他功能,甚至好用。
在这里插入图片描述
将制作完成的.9.png图片导入至项目中既可。左右各一个.9图
在这里插入图片描述
这样,前期的准备工作基本完成了

3.2 App界面实现

整体界面很简单,整体的布局示意图如图所示
在这里插入图片描述
主要分为两个文件实现:deepseek_layout.xmldeepseek_dialog_layout.xml,其中前者为整体的布局文件,后者为ListView的adapter的配套布局文件。两者的代码如下:
deepseek_layout.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#d8e0e8"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/msg_list_view"
        android:divider="#0000"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/input_text"
            android:hint="请输入您的问题..."
            android:maxLines="2"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="0dp" />
        <Button
            android:id="@+id/send_btn"
            android:text="发送"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

deepseek_dialog_layout.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <TextView
        android:textAlignment="center"
        android:id="@+id/currentDateTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:id="@+id/left_layout"
        android:layout_gravity="left"
        android:background="@drawable/msg_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:layout_gravity="center"
             android:layout_margin="10dp"
             android:textColor="#fff"
            android:id="@+id/left_msg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>
    <LinearLayout
         android:id="@+id/right_layout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="right"
         android:background="@drawable/msg_right" >
         <TextView
             android:id="@+id/right_msg"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
            android:layout_margin="10dp" />
     </LinearLayout>

</LinearLayout>

然后deepseek的请求,并完成ListView的赋值。关于deepseek的接口调用,参见使用C#控制台调用本地部署的DeepSeek。最终完成本项目的效果。

4、参考资料

1、.9.PNG是啥?

相关文章:

  • 【docker】安装SQLServer
  • DrRacket是一款专为Scheme和Racket编程语言设计的集成开发环境(IDE)
  • 重温Docker 构建
  • 3110. 字符串的分数
  • java版嘎嘎快充玉阳软件互联互通中电联云快充协议充电桩铁塔协议汽车单车一体充电系统源码uniapp
  • Thinkphp(TP)漏洞攻略
  • python基础语法中的内置函数与拆包
  • 我的创作纪念日暨六年编程路的回顾
  • Select多路转接
  • 深入理解 Bitmap 索引:原理、场景与应用案例
  • ccf2202邻域均值
  • PostgreSQL并行化内容
  • API接口文档(人力资源管理系统)
  • 给网站配置https访问
  • JVM(基础篇)
  • gitlab将其他分支设置为master分支
  • 机器学习之回归
  • MOSN(Modular Open Smart Network)是一款主要使用 Go 语言开发的云原生网络代理平台
  • Java中static final才是修饰常量的,单独的final并不能修饰常量这样理解对吗?
  • 【Linux】线程基础
  • 爱彼迎:一季度总收入约23亿美元,将拓展住宿以外的新领域
  • 5名中国公民在美国交通事故中遇难
  • 最火“五一”预订!小长假前两日多地接待游客量两位数增长,出境游订单井喷
  • 本周看啥|《乘风》迎来师姐们,《天赐》王蓉搭Ella
  • 玉渊谭天:美方多渠道主动接触中方希望谈关税
  • 安徽两位新任地级市政府党组书记亮相